Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chezmoi confused with exact_ and externals inside it #3414

Closed
stablestud opened this issue Dec 18, 2023 · 5 comments · Fixed by #3428
Closed

Chezmoi confused with exact_ and externals inside it #3414

stablestud opened this issue Dec 18, 2023 · 5 comments · Fixed by #3428
Labels
bug Something isn't working

Comments

@stablestud
Copy link

stablestud commented Dec 18, 2023

Describe the bug

  1. Chezmoi prints everytime incorrect/confusing warning messages about "changed" external files inside an exact_ directory, even when the external files have not changed.
# Note: .bashrc.d/ is exact_!
$ chezmoi apply
.bashrc.d/additional/fzf has changed since chezmoi last wrote it? overwrite/all-overwrite/skip/quit
  1. On a second run, answering o (to overwrite)
    the prompt changes to the following error message and the directory containing the externals has been deleted:
$ chezmoi apply
chezmoi: mkdir ~/.bashrc.d/additional/fzf: no such file or directory
$ ls ~/.bashrc.d/additional
ls: cannot access '~/.bashrc.d/additional': No such file or directory

Thus losing the content of ~/.bashrc.d/additional, which is unexpected

To reproduce

Have the folder exact_private_dot_bashrc.d with some files in it
and this .chezmoiexternals/fzf.toml.tmpl:

[".bashrc.d/additional/fzf/shell/completion.bash"]
        type = "archive-file"
        path = "shell/completion.bash"
        url = "https://github.com/junegunn/fzf/archive/refs/tags/0.43.0.tar.gz"
        stripComponents = 1
[".bashrc.d/additional/fzf/shell/key-bindings.bash"]
        type = "archive-file"
        path = "shell/key-bindings.bash"
        url = "https://github.com/junegunn/fzf/archive/refs/tags/0.43.0.tar.gz"
        stripComponents = 1

Note: .bashrc.d/additional is not defined in the exact_ directory, because it shall be only created for externals.

Expected behavior

Chezmoi shouldn't ask to overwrite the external files (as they weren't changed) and instead consider them to be part of the exact_ directory.
And even if the content has changed, being part of an exact_ directory, I would expect it to overwrite the files straight away.

Output of command with the --verbose flag

$ chezmoi --verbose apply
diff --git a/.bashrc.d/additional b/.bashrc.d/additional
deleted file mode 40775
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
--- a/.bashrc.d/additional
+++ /dev/null
.bashrc.d/additional/fzf has changed since chezmoi last wrote it? overwrite/all-overwrite/skip/quit

Output of chezmoi doctor

RESULT    CHECK                       MESSAGE
ok        version                     v2.42.3, commit 43a4f5790ef1b709de881d36afb0a61745efa34f, built at 2023-12-16T23:26:32Z, built by goreleaser
ok        latest-version              v2.42.3
ok        os-arch                     linux/amd64 (Ubuntu 22.04.3 LTS (Jammy Jellyfish))
ok        uname                       Linux ber-040 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
ok        go-version                  go1.21.5 (gc)
ok        executable                  /snap/chezmoi/809/chezmoi
ok        upgrade-method              snap-refresh
ok        config-file                 ~/.config/chezmoi/chezmoi.toml, last modified 2023-12-18T09:30:01+01:00
warning   source-dir                  ~/.local/share/chezmoi is a git working tree (dirty)
ok        suspicious-entries          no suspicious entries
warning   working-tree                ~/.local/share/chezmoi is a git working tree (dirty)
ok        dest-dir                    ~ is a directory
ok        umask                       002
ok        cd-command                  found /usr/bin/fish
ok        cd-args                     /usr/bin/fish
info      diff-command                not set
ok        edit-command                found /usr/bin/vi
ok        edit-args                   /usr/bin/vi
ok        git-command                 found /usr/bin/git, version 2.34.1
ok        merge-command               found /usr/bin/vimdiff
ok        shell-command               found /usr/bin/fish
ok        shell-args                  /usr/bin/fish
info      age-command                 age not found in $PATH
ok        gpg-command                 found /usr/bin/gpg, version 2.2.27
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
info      gopass-command              gopass not found in $PATH
ok        keepassxc-command           found /usr/bin/keepassxc-cli, version 2.6.6
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
@twpayne
Copy link
Owner

twpayne commented Dec 18, 2023

I suspect that this has the same root cause as #2132.

As a workaround, you should be able to run:

$ mkdir $(chezmoi source-path ~/.bashrc.d)/exact_additional
$ touch $(chezmoi source-path ~/.bashrc.d)/exact_additional/.keep

but note that I haven't tried this.

@twpayne twpayne added the bug Something isn't working label Dec 18, 2023
@twpayne twpayne added investigating This is a bit weird, not sure if this is a bug yet and removed bug Something isn't working labels Dec 21, 2023
@twpayne
Copy link
Owner

twpayne commented Dec 21, 2023

I tried to replicate this in #3428, but was unsuccessful. Do you have a small example that demonstrates the problem?

@stablestud
Copy link
Author

The files must already be "installed" into the target state. Then, once they're installed, running apply again is causing issues:

In your test you only execute chezmoi apply once, but the files are only removed on a second run.

The first run prints only the message that content has changed, which is not true
A second run fails with the error message described above

@twpayne twpayne added bug Something isn't working and removed investigating This is a bit weird, not sure if this is a bug yet labels Dec 24, 2023
@twpayne
Copy link
Owner

twpayne commented Dec 24, 2023

Thanks for spotting the problems with the test.

#3428 should now fix the problem. Would you be able to test this?

As a bit of background:

  1. The .bashrc.d/additional/fzf directory was implicit in the paths to the externals.
  2. After running chezmoi apply for the first time, chezmoi recorded that it created the .bashrc.d/additional/fzf directory.
  3. As .bashrc.d is an exact_ directory, chezmoi would remove the .bashrc.d/additional directory, since it wasn't explicit in the source state, but not store that fact that it had removed it.
  4. Later, chezmoi would get confused as the actual state of the .bashrc/additional/fzf (absent) did not match the state it observed at step 2.

#3428 fixes this by adding the internal concept of implicit directories, which are directories that are implicit in the path to an external, but are not actual directories in the source state.

@stablestud
Copy link
Author

I can confirm that your fix fixes the issue.

Tested and described problems went away.

Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants