twpayne / chezmoi

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

`add -T` does not create a template #545

Closed ehudkaldor closed 4 years ago

ehudkaldor commented 4 years ago

Describe the bug I followed the description on creating a template from the how-to page, but the file is added as is

To reproduce chezmoi add ~/.gitconfig

Expected behavior values existing in ~/.config/chezmoi/chezmoi.toml should be created as template markers, such as:

→ chezmoi add --verbose -T ~/.gitconfig
install -m 644 /dev/null /Users/NAME/.local/share/chezmoi/private_dot_gitconfig.tmpl
--- a/Users/NAME/.local/share/chezmoi/private_dot_gitconfig.tmpl
+++ b/Users/NAME/.local/share/chezmoi/private_dot_gitconfig.tmpl
@@ -0,0 +1,7 @@
+[user]
+   name = {{ name }}
+   email = {{ email }}

Output of command with --verbose

→ chezmoi add --verbose -T ~/.gitconfig
install -m 644 /dev/null /Users/NAME/.local/share/chezmoi/private_dot_gitconfig.tmpl
--- a/Users/NAME/.local/share/chezmoi/private_dot_gitconfig.tmpl
+++ b/Users/NAME/.local/share/chezmoi/private_dot_gitconfig.tmpl
@@ -0,0 +1,7 @@
+[user]
+   name = <REDACTED NAME>
+   email = <REDACTED EMAIL>

Output of chezmoi doctor

→ chezmoi doctor
     ok: version 1.7.10, commit a402f9eba1245b45de1aa0b05dda4b35c164f345, built at 2019-12-27T22:37:13Z
     ok: runtime.GOOS darwin, runtime.GOARCH amd64
     ok: /Users/NAME/.local/share/chezmoi (source directory, perm 700)
     ok: /Users/NAME (destination directory, perm 755)
     ok: /Users/NAME/.config/chezmoi/chezmoi.toml (configuration file)
     ok: /bin/zsh (shell)
     ok: /usr/bin/vi (editor)
     ok: /usr/bin/vimdiff (merge command)
     ok: /usr/bin/git (source VCS command, version 2.21.0)
warning: gpg (GnuPG, not found)
warning: op (1Password CLI, not found)
warning: bw (Bitwarden CLI, not found)
warning: gopass (gopass CLI, not found)
     ok: /usr/local/bin/keepassxc-cli (KeePassXC CLI, version 2.5.1)
warning: lpass (LastPass CLI, not found)
warning: pass (pass CLI, not found)
warning: vault (Vault CLI, not found)

Additional context my understanding is that when creating the template, it should be created with the values replaced by the template markers {{ email }}. but when i ran chezmoi add -T ~/.gitconfig, it added it as is, with the existing values.

twpayne commented 4 years ago

Thanks very much for reporting this. The underlying problem was that automatic template generation was disabled by default in #404 but I forgot to update the how-to documentation, which assumed that autotemplate was enabled by default.

I've updated the docs in #546. In the short term you can fix this by adding the --autotemplate to the chezmoi add command, for example:

chezmoi add -T --autotemplate ~/.gitconfig