Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent failure when adding a directory without --recursive #668

Closed
olibre opened this issue Apr 14, 2020 · 2 comments · Fixed by #679
Closed

Silent failure when adding a directory without --recursive #668

olibre opened this issue Apr 14, 2020 · 2 comments · Fixed by #679
Labels
bug Something isn't working

Comments

@olibre
Copy link

olibre commented Apr 14, 2020

Describe the bug

chezmoi add should warn when adding a directory without --recursive.

To reproduce

$ sudo dnf install snapd
$ sudo ln -s /var/lib/snapd/snap /snap
$ sudo snap install chezmoi --classic

$ snap run chezmoi --version
chezmoi version 1.7.19, commit c4dd79633ab5d7263146128847f2b429f0603c55, built at 2020-04-06T22:06:15Z, built by goreleaser

$ snap run chezmoi add -v ~/.config/htop/

No output, no error.

$ snap run chezmoi cd
$ git status

Nothing added!

Expected behavior

Two possible fixes:

  1. Warning + Suggest -r option
    $ snap run chezmoi add ~/.config/htop/
    Warn: did not add ~/.config/htop/ because it is a directory
          use option -r to add a directory recursively
    
  2. Automatically add recursively a directory
    This is the default Git behavior.
    As chezmoi and git share same command name add many coders expect this second behavior.
    Therefore -r option becomes implicit (and may become deprecated).

Output of chezmoi doctor

$ snap run chezmoi doctor
WARNING: cgroup v2 is not fully supported yet, proceeding with partial confinement
     ok: version 1.7.19, commit c4dd79633ab5d7263146128847f2b429f0603c55, built at 2020-04-06T22:06:15Z, built by goreleaser
     ok: runtime.GOOS linux, runtime.GOARCH amd64
     ok: /home/o/.local/share/chezmoi (source directory, perm 700)
     ok: /home/o (destination directory, perm 700)
warning: /home/o/.config/chezmoi/chezmoi.toml (configuration file)
     ok: /bin/bash (shell)
     ok: /usr/bin/vi (editor)
     ok: /usr/bin/vimdiff (merge command)
     ok: /usr/bin/git (source VCS command, version 2.25.2)
     ok: /usr/bin/gpg (GnuPG, version 2.2.18)
warning: op (1Password CLI, not found)
warning: bw (Bitwarden CLI, not found)
warning: gopass (gopass CLI, not found)
warning: keepassxc-cli (KeePassXC CLI, not found)
warning: lpass (LastPass CLI, not found)
warning: pass (pass CLI, not found)
warning: vault (Vault CLI, not found)

Additional context

I am using Fedora 31 and currently comparing chezmoi, yadm and dotdrop: https://github.com/olibre/GreatPractices#dotfiles-managers

@twpayne twpayne added the bug Something isn't working label Apr 14, 2020
@twpayne twpayne added investigating This is a bit weird, not sure if this is a bug yet and removed bug Something isn't working labels Apr 15, 2020
@twpayne
Copy link
Owner

twpayne commented Apr 15, 2020

I'm currently unable to reproduce this on any other system (I've tried Ubuntu/snap and macOS/homebrew), and have added a specific test for it in #670, which passes on Ubuntu, macOS, and Windows.

I notice that the output of chezmoi doctor includes:

WARNING: cgroup v2 is not fully supported yet, proceeding with partial confinement

Is it possible that snap is not running chezmoi correctly on your machine?

Please could you try running the chezmoi binary directly, i.e.:

$ /snap/chezmoi/current/chezmoi add -v ~/.config/htop/
$ /snap/chezmoi/current/chezmoi doctor

Does the bug still occur without snap?

@twpayne
Copy link
Owner

twpayne commented Apr 18, 2020

OK, I now understand what is going on here. What's happening is:

  1. The directory ~/.config/htop already exists and is not empty.
  2. If the directory did not exist (and the steps to reproduce do not include creating it) then chezmoi would report a "no such file or directory" error.
  3. If the directory were empty, then chezmoi would automatically add a .keep file, but the directory is not empty, so it doesn't.
  4. Consequently, an empty directory gets added to the source state, which is ignored by git status.

@twpayne twpayne added bug Something isn't working and removed investigating This is a bit weird, not sure if this is a bug yet labels Apr 18, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants