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

Ignored files populated by chezmoiexternal are not ignored #3559

Closed
mbologna opened this issue Feb 12, 2024 · 4 comments
Closed

Ignored files populated by chezmoiexternal are not ignored #3559

mbologna opened this issue Feb 12, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@mbologna
Copy link

mbologna commented Feb 12, 2024

Describe the bug

Two files are populated by .chezmoiexternal.
The same two files are also ignored in .chezmoiignore.
Those files are not ignored.

To reproduce

$ cat .chezmoiexternal

{{- if eq .chezmoi.os "linux" }}
["bin/starship"]
    type = "archive-file"
    url = "https://github.com/starship/starship/releases/latest/download/starship-x86_64-unknown-linux-gnu.tar.gz"
    path = "starship"
["bin/fastfetch"]
    type = "archive-file"
    url = "https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-x86_64.zip"
    path = "fastfetch-linux-x86_64/usr/bin/fastfetch"
{{- end }}

$ cat .chezmoiignore

README.md
{{- if ne .chezmoi.os "linux" }}
bin/fastfetch
bin/starship
{{- end }}

Test on Linux:

chezmoi$ git clean -fd && rm -f ~/bin/starship ~/bin/fastfetch && chezmoi apply -R -v && ls -l ~/bin/starship && chezmoi add ~/bin/ && git status

Removing bin/executable_fastfetch
Removing bin/executable_starship
added: bin/fastfetch
added: bin/starship
-rwxr-xr-x 1 michele michele 9738960 Feb 12 10:42 /home/michele/bin/starship 

On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        bin/executable_fastfetch
        bin/executable_starship

Expected behavior

fastfetch and starship are ignored by chezmoi on Linux and not added to the source state (thus they do not show up in git status).

Output of command with the --verbose flag

chezmoi $ git clean -fd && chezmoi --verbose add ~/bin

No output, return code 0

Output of chezmoi doctor

$ chezmoi doctor

RESULT    CHECK                       MESSAGE
ok        version                     v2.46.1, commit c65f66a5f1a990ffeb4d7e3f53320cb061f91513, built at 2024-02-11T16:33:13Z, built by goreleaser
ok        latest-version              v2.46.1
ok        os-arch                     linux/amd64 (Ubuntu 22.04.3 LTS (Jammy Jellyfish))
ok        uname                       Linux e4e02b8347af 5.15.0-92-generic #102-Ubuntu SMP Wed Jan 10 09:33:48 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
ok        go-version                  go1.22.0 (gc)
ok        executable                  /usr/bin/chezmoi
ok        upgrade-method              upgrade-package
ok        config-file                 ~/.config/chezmoi/chezmoi.toml, last modified 2024-02-12T09:46:19Z
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                       022
ok        cd-command                  found /bin/bash
ok        cd-args                     /bin/bash
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 /bin/bash
ok        shell-args                  /bin/bash
info      age-command                 age not found in $PATH
info      gpg-command                 gpg not found in $PATH
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
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

In ~/bin there are scripts that are managed by chezmoi so I cannot just ignore ~/bin

@bradenhilton
Copy link
Collaborator

docker run -it alpine:latest
/ # apk update
...
OK: 22982 distinct packages available
/ # apk add curl
...
OK: 12 MiB in 23 packages
/ # apk add neovim
...
OK: 34 MiB in 34 packages
/ # sh -c "$(curl -fsLS get.chezmoi.io)"
info found version 2.46.1 for latest/linux/amd64
info installed ./bin/chezmoi
/ # chezmoi init
/ # cd $(chezmoi source-path)
~/.local/share/chezmoi # nvim .chezmoiexternal.toml
~/.local/share/chezmoi # cat .chezmoiexternal.toml
{{- if eq .chezmoi.os "linux" }}
["bin/starship"]
    type = "archive-file"
    url = "https://github.com/starship/starship/releases/latest/download/starship-x86_64-unknown-linux-gnu.tar.gz"
    path = "starship"
["bin/fastfetch"]
    type = "archive-file"
    url = "https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-x86_64.zip"
    path = "fastfetch-linux-x86_64/usr/bin/fastfetch"
{{- end }}
~/.local/share/chezmoi # nvim .chezmoiignore
~/.local/share/chezmoi # cat .chezmoiignore
README.md
{{- if ne .chezmoi.os "linux" }}
bin/fastfetch
bin/starship
{{- end }}
~/.local/share/chezmoi # chezmoi apply
~/.local/share/chezmoi # cd
~ # chezmoi add ./bin
~ # chezmoi managed
chezmoi: bin/fastfetch: inconsistent state (/root/.local/share/chezmoi/bin/executable_fastfetch, https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-x86_64.zip defined in /root/.local/share/chezmoi/.chezmoiexternal.toml)
bin/starship: inconsistent state (/root/.local/share/chezmoi/bin/executable_starship, https://github.com/starship/starship/releases/latest/download/starship-x86_64-unknown-linux-gnu.tar.gz defined in /root/.local/share/chezmoi/.chezmoiexternal.toml)

@mbologna
Copy link
Author

~ # chezmoi add ./bin
~ # chezmoi managed
chezmoi: bin/fastfetch: inconsistent state (/root/.local/share/chezmoi/bin/executable_fastfetch, https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-x86_64.zip defined in /root/.local/share/chezmoi/.chezmoiexternal.toml)
bin/starship: inconsistent state (/root/.local/share/chezmoi/bin/executable_starship, https://github.com/starship/starship/releases/latest/download/starship-x86_64-unknown-linux-gnu.tar.gz defined in /root/.local/share/chezmoi/.chezmoiexternal.toml)

Yes, I reproduced it with alpine as well:

~/.local/share/chezmoi # git status 
On branch master
nothing to commit, working tree clean
~/.local/share/chezmoi # tree .
.
└── bin
    ├── bar
    └── foo

1 directories, 2 files
~/.local/share/chezmoi # cat .chezmoiexternal.toml .chezmoiignore 
{{- if eq .chezmoi.os "linux" }}
["bin/starship"]
    type = "archive-file"
    url = "https://github.com/starship/starship/releases/latest/download/starship-x86_64-unknown-linux-gnu.tar.gz"
    path = "starship"
["bin/fastfetch"]
    type = "archive-file"
    url = "https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-x86_64.zip"
    path = "fastfetch-linux-x86_64/usr/bin/fastfetch"
{{- end }}
README.md
{{- if ne .chezmoi.os "linux" }}
bin/fastfetch
bin/starship
{{- end }}
~/.local/share/chezmoi # tree ~/bin/
/root/bin/
├── bar
├── fastfetch
├── foo
└── starship

0 directories, 4 files
~/.local/share/chezmoi # chezmoi add ~/bin/
~/.local/share/chezmoi # chezmoi managed
chezmoi: bin/fastfetch: inconsistent state (/root/.local/share/chezmoi/bin/executable_fastfetch, https://github.com/fastfetch-cli/fastfetch/releases/latest/download/fastfetch-linux-x86_64.zip defined in /root/.local/share/chezmoi/.chezmoiexternal.toml)
bin/starship: inconsistent state (/root/.local/share/chezmoi/bin/executable_starship, https://github.com/starship/starship/releases/latest/download/starship-x86_64-unknown-linux-gnu.tar.gz defined in /root/.local/share/chezmoi/.chezmoiexternal.toml)
~/.local/share/chezmoi # git status 
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        bin/executable_fastfetch
        bin/executable_starship

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

@bradenhilton bradenhilton added the bug Something isn't working label Feb 12, 2024
@twpayne twpayne added support Support request and removed bug Something isn't working labels Feb 18, 2024
@twpayne
Copy link
Owner

twpayne commented Feb 18, 2024

bin/starship and bin/fastfetch are missing

    executable = true

in your .chezmoiexternal.toml file.

Wait, that's not correct.

@twpayne twpayne added bug Something isn't working and removed support Support request labels Feb 18, 2024
@twpayne
Copy link
Owner

twpayne commented Feb 18, 2024

Under the hood, this is the same issue as #1574.

Note that bin/starship and bin/fastfetch are not ignored. They're only ignored on non-Linux machines.

What's happening here is that two files which are already defined in .chezmoiexternal.toml are also being added with chezmoi add, and the resulting state is inconsistent.

chezmoi should not allow files to be added if they're already defined as externals. I'll update the description of #1574.

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

No branches or pull requests

3 participants