twpayne / chezmoi

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

generate git-commit-message fails: 'unsupported XY: ".M"' #3344

Closed azmodude closed 12 months ago

azmodude commented 12 months ago

Describe the bug

Trying the newly implemented chezmoi generate git-commit-message fails with

chezmoi: template: COMMIT_MESSAGE:7:74: executing "COMMIT_MESSAGE" at <fail .>: error calling fail: unsupported XY: ".M"

To reproduce

Run chezmoi generate git-commit-message with just the default options for commits (read: none, template not modified) in ~/.config/chezmoi/chezmoi.toml.

Expected behavior

Output a commit message with changes in source directory to be commited.

Output of command with the --verbose flag

chezmoi --verbose generate git-commit-message
chezmoi: template: COMMIT_MESSAGE:7:74: executing "COMMIT_MESSAGE" at <fail .>: error calling fail: unsupported XY: ".M"

Output of chezmoi doctor

chezmoi doctor
RESULT    CHECK                       MESSAGE
ok        version                     v2.41.0, commit 4a5f006fede66f8e2b9213bfe872244eb2b2cfd8, built at 2023-11-14T02:41:18Z, built by goreleaser
ok        latest-version              v2.41.0
ok        os-arch                     darwin/arm64
ok        uname                       Darwin v100wpxmk1wj04a 22.6.0 Darwin Kernel Version 22.6.0: Wed Oct  4 21:26:55 PDT 2023; root:xnu-8796.141.3.701.17~4/RELEASE_ARM64_T6020 arm64
ok        go-version                  go1.21.4 (gc)
ok        executable                  ~/bin/chezmoi
ok        upgrade-method              replace-executable
ok        config-file                 ~/.config/chezmoi/chezmoi.toml, last modified 2023-11-15T11:59:51+01:00
warning   source-dir                  ~/.local/share/chezmoi is a git working tree (dirty)
warning   suspicious-entries          ~/.local/share/chezmoi/.chezmoi.toml.personal.tmpl and ~/.local/share/chezmoi/.chezmoi.toml.work.tmpl
warning   working-tree                ~/.local/share/chezmoi is a git working tree (dirty)
ok        dest-dir                    ~ is a directory
ok        umask                       022
ok        cd-command                  found /bin/zsh
ok        cd-args                     /bin/zsh
info      diff-command                not set
ok        edit-command                found ~/bin/nvim
ok        edit-args                   ~/bin/nvim
ok        git-command                 found /usr/bin/git, version 2.39.3
ok        merge-command               found ~/bin/nvim
ok        shell-command               found /bin/zsh
ok        shell-args                  /bin/zsh
info      age-command                 age not found in $PATH
ok        gpg-command                 found /opt/fi/util/gpg/bin/gpg, version 2.4.3
info      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
ok        gopass-command              found ~/bin/gopass, version 1.15.5
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

Add any other context about the problem here.

twpayne commented 12 months ago

What is the output of

git status --ignored --porcelain=v2

in your source directory?

azmodude commented 12 months ago

It's

git status --ignored --porcelain=v2
1 .M N... 100644 100644 100644 54276930d8aaf52fffff3c90e4aaae21beb3c7d5 54276930d8aaf52fffff3c90e4aaae21beb3c7d5 .chezmoi.toml.work.tmpl
1 .M N... 100644 100644 100644 7d84c798c4e58c9a13cd8ec8ab06e40ee7ca0bd7 7d84c798c4e58c9a13cd8ec8ab06e40ee7ca0bd7 readonly_dot_zshrc.tmpl
twpayne commented 12 months ago

You have changes to tracked files that have not been added to the index. You need to git add the files that you want to commit.

azmodude commented 12 months ago

Oops, now I feel kind of embarrassed... I definitely thought I tried that earlier before posting this bug report, but obviously I did not. Adding the files to the index and then generating the commit-message works just fine.

Sorry for wasting your time and thanks for your work!

twpayne commented 12 months ago

No worries! On reflection, I think chezmoi generate git-commit-message should generate a commit message for the changes in the index and not fail in this case. I'll open a PR.