twpayne / chezmoi

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

`error: cannot pull with rebase: You have unstaged changes` #2495

Closed anhdle14 closed 2 years ago

anhdle14 commented 2 years ago

What exactly are you trying to do?

chezmoi apply failed. with error:

❯ chezmoi apply
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.
chezmoi: exit status 128

What have you tried so far?

Also tried to use git pull both directly or via chezmoi:

All returns nothing wrong.

Describe what you have tried so far.

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

$ chezmoi --verbose update
Host key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
+--[ED25519 256]--+
|                 |
|     .           |
|      o          |
|     o o o  .    |
|     .B S oo     |
|     =+^ =...    |
|    oo#o@.o.     |
|    E+.&.=o      |
|    ooo.X=.      |
+----[SHA256]-----+
Already up to date.
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.
chezmoi: exit status 128

Output of chezmoi doctor

```console RESULT CHECK MESSAGE ok version v2.25.0, commit b3a8879e30a20134c9bef48646055e57aa78d8c5, built at 2022-10-13T13:22:21Z, built by Homebrew ok latest-version v2.25.0 ok os-arch darwin/arm64 ok uname Darwin 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:19:52 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T6000 arm64 ok go-version go1.19.2 (gc) ok executable ~/homebrew/bin/chezmoi ok upgrade-method brew-upgrade ok config-file ~/.config/chezmoi/chezmoi.yaml, last modified 2022-10-26T22:50:58+09:00 ok source-dir ~/.local/share/chezmoi is a git working tree (clean) warning suspicious-entries ~/.local/share/chezmoi/.chezmoidata.yaml.tpml and ~/.local/share/chezmoi/dot_config/chezmoi/chezmoi.yaml.tmpl ok working-tree ~/.local/share/chezmoi is a git working tree (clean) ok dest-dir ~ is a directory ok umask 022 ok cd-command found /bin/zsh ok cd-args /bin/zsh ok diff-command found ~/homebrew/bin/delta ok edit-command found ~/.local/nvim/bin/nvim ok edit-args ~/.local/nvim/bin/nvim ok git-command found ~/homebrew/bin/git, version 2.38.1 ok merge-command found ~/homebrew/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 ~/homebrew/bin/gpg, version 2.3.8 info pinentry-command not set info 1password-command op not found in $PATH ok bitwarden-command found ~/homebrew/bin/bw, version 2022.10.0 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 ok lastpass-command found ~/homebrew/bin/lpass, version 1.3.3 info pass-command pass not found in $PATH info passhole-command ph not found in $PATH ok vault-command found ~/homebrew/bin/vault, version 1.12.0 info secret-command not set ```

Additional context

Add any other context about the problem here.

twpayne commented 2 years ago

This error is coming from git, not chezmoi.

I suspect that you have a git-repo external where the local working tree has been modified. When you run chezmoi apply, chezmoi runs git pull --rebase in the external's directory, which is then failing due to the local changes.

You can verify this by running

$ chezmoi apply --debug

which should show you exactly what is failing.

I'll open a PR to improve chezmoi's error message here.

halostatue commented 2 years ago

This is a git message because you don’t have pull.autostash = true (which, while a really good thing to do, can occasionally result in stashes that result in conflicts if you have enough changes) and have a dirty git index.

chezmoi git status should provide useful information. as to what the modified files are. If you don’t care, you can force the pull with chezmoi git pull -- --autostash --rebase.

@twpayne Do we want to use --autostash by default or have a chezmoi configuration that would apply that? I never see this, because I have pull.autostash = true in my .gitconfig, and it’s safe ~99.9% of the time (that last 0.1%, though, can result in some really fun merge collision resolutions).

twpayne commented 2 years ago

Ah, thanks for the tip on --autostash @halostatue. Yes, I think it makes sense to have autostash as the default. A user can override it by setting pull.args for the repo in their .chezmoiexternal.<format>.

twpayne commented 2 years ago

2501 should make this easier to debug from now on by including the external's path in the error message.

Hopefully this issue is now resolved. Please re-open if necessary.