twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.

Home Page:https://www.chezmoi.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Config variables `autoAdd = true` and `autoCommit = true` don't seem to add or commit changes

halloleo opened this issue · comments

Describe the bug

I think I found a bug in chezmoi -- if I understand things correctly:

The config variables autoAdd = true and autoCommit = true don't seem to add or commit changes in the source directory to the git repo of that directory.

To reproduce

Start with a clean git repo of the source directory:

$ chezmoi git status
On branch main
nothing to commit, working tree clean

and the following complete ~/.config/chezmoi/chezmoi.toml:

# chezmoi config

sourceDir = "~/Dropbox/sync/chezmoi" # on Dropbox machines

autoAdd = true
autoCommit = true

Then add a new file ~/.inputrc (which is not yet in chezmoi) to the source directory via

$$$ cz --verbose add ~/.inputrc
diff --git a/dot_inputrc b/dot_inputrc
new file mode 100644
index 0000000000000000000000000000000000000000..eaca67728983926b78c65ca8cce2f2857bf31320
--- /dev/null
+++ b/dot_inputrc
@@ -0,0 +1,2 @@
+set colored-stats off
+set completion-ignore-case on

Then check chezmoi's git repo:

$$$ chezmoi git status
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        dot_inputrc

nothing added to commit but untracked files present (use "git add" to track)

Expected behaviour

I expected that the file dot_inputrc is added to the repository and its current version is committed to the repo.

Output of chezmoi doctor

$ chezmoi doctor
RESULT    CHECK                       MESSAGE
ok        version                     v2.47.0, commit 39bd915f446068862cc3064edb6dbeee795785ca, built at 2024-02-25T20:33:32Z, built by Homebrew
warning   latest-version              v2.49.0
ok        os-arch                     darwin/arm64
ok        uname                       Darwin typedstrongly.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64
ok        go-version                  go1.22.0 (gc)
ok        executable                  /opt/homebrew/bin/chezmoi
ok        upgrade-method              brew-upgrade
ok        config-file                 ~/.config/chezmoi/chezmoi.toml, last modified 2024-06-17T12:32:49+10:00
warning   source-dir                  ~/Dropbox/sync/chezmoi is a git working tree (dirty)
ok        suspicious-entries          no suspicious entries
warning   working-tree                ~/Dropbox/sync/chezmoi is a git working tree (dirty)
ok        dest-dir                    ~ is a directory
ok        umask                       022
ok        cd-command                  found /opt/homebrew/bin/xonsh
ok        cd-args                     /opt/homebrew/bin/xonsh
info      diff-command                not set
ok        edit-command                found /usr/bin/vi
ok        edit-args                   /usr/bin/vi
ok        git-command                 found /opt/homebrew/bin/git, version 2.44.0
ok        merge-command               found ~/opt/link/bin/merge_for_chezmoi.sh
ok        shell-command               found /opt/homebrew/bin/xonsh
ok        shell-args                  /opt/homebrew/bin/xonsh
info      age-command                 age not found in $PATH
ok        gpg-command                 found /opt/homebrew/bin/gpg, version 2.4.5info      pinentry-command            not set
info      1password-command           op not found in $PATH
info      bitwarden-command           bw not found in $PATH
info      bitwarden-secrets-command   bws not found in $PATH
info      dashlane-command            dcli not found in $PATH
info      doppler-command             doppler not found in $PATH
info      gopass-command              gopass not found in $PATH
info      keepassxc-command           keepassxc-cli not found in $PATH
info      keepassxc-db                not set
info      keeper-command              keeper not found in $PATH
info      lastpass-command            lpass not found in $PATH
info      pass-command                pass not found in $PATH
info      passhole-command            ph not found in $PATH
info      rbw-command                 rbw not found in $PATH
info      vault-command               vault not found in $PATH
info      vlt-command                 vlt not found in $PATH
info      secret-command              not set

Additional context

I tried using autoAdd alone, but that didn't bring any change to the git repo either.

The variables are git.autoAdd and git.autoCommit, as described in the documentation.

Aaaaah, of course.

I was fiddling and trying for a while and I had read through the doco, but I missed the bit that these vars have to be part of the [git] subsection. My bad. I now can confirm when the config is correct, it works as expected. 😃

Thanks heaps for chiming in here. You made my day.