twpayne / chezmoi

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

Support source directory being a git submodule #2482

Closed YHYJ closed 1 year ago

YHYJ commented 2 years ago

Describe the bug

[git]
    autoCommit = true
    autoPush = false

After run chezmoi re-add, autoCommit reports an error:

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

To reproduce

  1. Set autoCommit = true
  2. Run chezmoi --destination / re-add (I set the destination directory /)

Expected behavior

autoCommit successfully executed

Output of command with the --verbose flag

$ chezmoi --destination / re-add --verbose
...... some file changes ......
chezmoi: template: commit_message:5:74: executing "commit_message" at <fail .>: error calling fail: unsupported XY: ".M"

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE warning version v2.25.0, built at 2022-10-14T10:20:55Z ok latest-version v2.25.0 ok os-arch linux/amd64 (Arch Linux) ok uname Linux MyPC 6.0.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 15 Oct 2022 14:00:49 +0000 x86_64 GNU/Linux ok go-version go1.19.2 (gc) ok executable /usr/bin/chezmoi ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2022-10-22T22:14:48+08:00 warning source-dir ~/Documents/System/Profile is a git working tree (dirty) warning suspicious-entries ~/Documents/System/Profile~/private_dot_config/chezmoi/chezmoi.toml warning working-tree ~/Documents/System 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 /usr/bin/nvim ok edit-args /usr/bin/nvim ok git-command found /usr/bin/git, version 2.38.1 ok merge-command found /usr/bin/vimdiff ok shell-command found /bin/zsh ok shell-args /bin/zsh info age-command age not found in $PATH ok gpg-command found /usr/bin/gpg, version 2.2.40 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw 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 ok pass-command found /usr/bin/pass, version 1.7.4 info passhole-command ph not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```

Additional context

Add any other context about the problem here.

twpayne commented 2 years ago

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

This occurs because the git repo has got into a state that chezmoi cannot generate a commit message for.

What's the output of the following commands?

$ chezmoi cd
$ git status
$ git status --ignored --porcelain=v2
YHYJ commented 2 years ago

2022-10-25_09-07-26

  1. I set sourceDir = "~/Documents/System/Profile", and 'Profile' is a git submodule of 'System', chezmoi cd goes to 'System', not 'Profile'
twpayne commented 2 years ago

Thank you for the follow-up.

I am confused by the output of git status --ignored --porcelain=v2. In all lines of the output the file permissions (columns 4, 5, and 6) are unchanged at 100644, and the file content hashes (columns 7 and 8) are also unchanged, and yet the XY field (column 2) shows .M, indicating that something has been modified. If you're interested in the details, see the man page for git status.

Do you know what could have been modified? Could there be some other attributes not tracked by git or some kind of ACL changes?

What's the output of

$ chezmoi cd
$ git diff

?

twpayne commented 2 years ago

As a side thread, ~/.config/chezmoi/chezmoi.toml should not be managed by chezmoi. You should use a config file template instead.

twpayne commented 2 years ago
  1. I set sourceDir = "~/Documents/System/Profile", and 'Profile' is a git submodule of 'System', chezmoi cd goes to 'System', not 'Profile'

Ah, on further reflection, I think this is the cause. Thank you for identifying this. I'm reasonably sure that chezmoi's autoCommit and autoPush do not currently support changes in git submodules. Assuming this is true, I'll update this issue's descriptions and tags.

twpayne commented 2 years ago

To further confirm this, the output of chezmoi doctor shows that chezmoi is very confused by the use of git submodules:

RESULT    CHECK                MESSAGE
...
warning   source-dir           ~/Documents/System/Profile is a git working tree (dirty)
warning   suspicious-entries   ~/Documents/System/Profile~/private_dot_config/chezmoi/chezmoi.toml
warning   working-tree         ~/Documents/System is a git working tree (dirty)
YHYJ commented 2 years ago

Thanks for your answer.

I think .M is 'modified' meaning i modified the file? git diff shows those changes.

I got config file template,thanks.

YHYJ commented 2 years ago

To further confirm this, the output of chezmoi doctor shows that chezmoi is very confused by the use of git submodules:

RESULT    CHECK                MESSAGE
...
warning   source-dir           ~/Documents/System/Profile is a git working tree (dirty)
warning   suspicious-entries   ~/Documents/System/Profile~/private_dot_config/chezmoi/chezmoi.toml
warning   working-tree         ~/Documents/System is a git working tree (dirty)

Yes, there is no such confusion without using git submodule

twpayne commented 2 years ago

I'm not very familiar with git submodules, and every time I've tried to used git submodules I've encountered lots of problems, so I'll accept a PR that fixes this, but do not plan to work on this myself.

halostatue commented 2 years ago

I’ve done a lot with submodules as a consumer, but I’m not sure how a test for this would be set up. Ideally, @YHYJ could set up a repo-set that models this—or perhaps a docker image so that we can run this in a wholly isolated way and then we might be able to simulate it.

YHYJ commented 2 years ago

I’ve done a lot with submodules as a consumer, but I’m not sure how a test for this would be set up. Ideally, @YHYJ could set up a repo-set that models this—or perhaps a docker image so that we can run this in a wholly isolated way and then we might be able to simulate it.

I'm not very familiar with git submodules, what this means and how to do it.

halostatue commented 2 years ago

What I’d be looking for in order to be able to debug this would be a repo setup that exhibits the same as your configuration does, but with as few files as possible so we can try to understand this.

Somehow, your source directory is a git submodule, right? Which means it’s a submodule of something else. If you can make a pair of clean repos (a simulated source directory, and a repo which has that as a submodule) that can be used with Chezmoi to show this, then I think we can investigate. As of right now, I have no clue how to investigate what you’ve reported.

YHYJ commented 2 years ago

Now I have a repo chezmoi-test which has a submodule dotfile-test, please read chezmoi-test/README.md first.

dotfile-test only stores the neofetch configuration file.

halostatue commented 2 years ago

Thanks. I may be able to look at this on the weekend; if not, it will probably be December before I can do so.

YHYJ commented 2 years ago

Thanks for your work!

halostatue commented 1 year ago

I’m hitting some walls trying to get everything set up to test this; I’ve forked your original repo and added some testing details to it: https://github.com/halostatue/chezmoi-submodule-test

At the moment, I’m hitting issues with SSH agent forwarding and docker, so it’s not directly related, and I’m trying to work in a wholly isolated environment.

Run with ./run.

twpayne commented 1 year ago

As this is a specific case that hasn't been updated in over six months, I'll close this. Please re-open if needed.