twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
13.4k stars 493 forks source link

chezmoi does not warn when dropping template file #521

Closed Rubonnek closed 3 years ago

Rubonnek commented 4 years ago

Describe the bug Say myfile.config.tmpl exists in the chezmoi repo, chezmoi add myfile.config removes the template.

To reproduce

chezmoi add myfile.config #while myfile.config.tmpl exists in chezmoi repo

Expected behavior Perhaps chezmoi should warn the user that a template file would be removed by this action and then perhaps either prompt the user to add the file or simply do nothing about it.

Output of command with --verbose

$ chezmoi add myfile.config --verbose
rm -rf /home/wilson/.local/share/chezmoi/myfile.config.tmpl
install -m 644 /dev/null /home/wilson/.local/share/chezmoi/myfile.config
--- a/home/wilson/.local/share/chezmoi/myfile.config
+++ b/home/wilson/.local/share/chezmoi/myfile.config
@@ -0,0 +1,1 @@
+test

Output of chezmoi doctor

$ chezmoi doctor
warning: version 1.7.6
     ok: runtime.GOOS linux, runtime.GOARCH amd64
     ok: /home/wilson/.local/share/chezmoi (source directory, perm 700)
     ok: /home/wilson (destination directory, perm 700)
     ok: /home/wilson/.config/chezmoi/chezmoi.toml (configuration file)
     ok: /bin/zsh (shell)
     ok: /usr/bin/vim (editor)
     ok: /usr/bin/vimdiff (merge command)
     ok: /usr/bin/git (source VCS command, version 2.24.1)
     ok: /usr/bin/gpg (GnuPG, version 2.2.19)
warning: op (1Password CLI, not found)
warning: bw (Bitwarden CLI, not found)
warning: /usr/bin/gopass (gopass CLI)
warning: keepassxc-cli (KeePassXC CLI, not found)
warning: lpass (LastPass CLI, not found)
     ok: /usr/bin/pass (pass CLI, version 1.7.3)
     ok: /usr/bin/vault (Vault CLI, version 1.2.0)

Additional context I still have the bad habit of using chezmoi add instead of chezmoi edit for files I already added to the repo. I'd rather have an early warning than blow away a template file that might have not been committed to the repo.

twpayne commented 4 years ago

Thanks for proposing this. This definitely make chezmoi more user friendly. I've just tagged version 1.7.9 which includes a fix for this - it'll take about 10 minutes to appear on the releases page.

Rubonnek commented 4 years ago

Thank you!

Rubonnek commented 3 years ago

I'm able to replicate this issue once again in chezmoi version v2.0.10. Seems to be a regression.

To reproduce:

echo 'a' > .myfile.config
chezmoi add -T .myfile.config
chezmoi add .myfile.config
Rubonnek commented 3 years ago

Thank you!!