twpayne / chezmoi

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

files being copied to target directory despite appearing in .chezmoiignore #2784

Closed devinnasar closed 1 year ago

devinnasar commented 1 year ago

What exactly are you trying to do?

I have a file contained in my .chezmoiignore file that is still being copied from my chezmoi source directory to the target directory. I am trying to accomplish the iterm2 setup referenced here: https://github.com/renemarc/dotfiles/tree/master/dot_config/iterm. Currently what's happening is that .chezmoiignore is failing to ignore com.googlecode.iterm2.plist, so it attempts to copy the file directly and create a symlink to it at the same path and prevents chezmoi apply -v from running correctly

Describe in as much detail as possible.

~/.local/share/chezmoi/.chezmoiignore:

# -*-mode:gitignore-*- vim:ft=gitignore

# ~/.local/share/chezmoi/.chezmoiignore
# =============================================================================
# Read by chezmoi when chosing repository files to copy to home directory.
#
# This list defines globs to ignore, and supports Go's text/template language.
# See https://www.chezmoi.io/docs/reference/#chezmoiignore

*.gz
LICENSE
README.md
com.googlecode.iterm2.plist

# Ignore non-macOS files.
{{ if ne .chezmoi.os "darwin" -}}
dot_config/iterm
dot_Brewfile
{{- end }}

# Ignore non-Windows files.
{{ if ne .chezmoi.os "windows" -}}chezm
dot_config/windows_terminal
{{- end }}

Source directory:

~/.local/share/chezmoi/dot_config/iterm2_profile
↳ tree                                                      
.
├── symlink_com.googlecode.iterm2.plist.tmpl
└── com.googlecode.iterm2.plist

Errors:

~/.local/share/chezmoi/dot_config/iterm2_profile
↳ chezmoi apply -v
chezmoi: .config/iterm2_profile/com.googlecode.iterm2.plist: inconsistent state (/Users/devin.nasar/.local/share/chezmoi/dot_config/iterm2_profile/com.googlecode.iterm2.plist, /Users/devin.nasar/.local/share/chezmoi/dot_config/iterm2_profile/symlink_com.googlecode.iterm2.plist.tmpl)

The template is trying to render a symlink file to ~/.config/iterm2_profile/com.googlecode.iterm2.plist pointing back to the file located in my chezmoi repo at ~/.local/share/chezmoi/dot_config/iterm2_profile/com.googlecode.iterm2.plist. But chezmoi is also trying to copy the file to the same path that the symlink is rendering to. My expectation is that because I've specified com.googlecode.iterm2.plist in .chezmoiignore, that chezmoi will not copy the file and then generate the symlink instead.

What is wrong with my .chezmoiignore file for this not to be happening? The ultimate point of this is for iterm2 to be configured to point at the symlink so that changes set in iterm2's gui will easily find their way back to the chezmoi repo. HOWEVER, it's more concerning to me that .chezmoiignore just doesn't work the way that I'm expecting.

What have you tried so far?

Many many combinations of paths in .chezmoiignore, changing my template file symlink path. I've been able to get it to the point where both com.googlecode.iterm2.plist (symlink) and the actual file with a separate filename are BOTH being copied into the target directory, which is still not what I want.

Where else have you checked for solutions?

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

see above

Output of chezmoi doctor

```console RESULT CHECK MESSAGE ok version v2.31.0, commit 4d2bc846212e27fae1e5bbd45d70e00908da603b, built at 2023-02-17T11:19:43Z, built by Homebrew ok latest-version v2.31.0 ok os-arch darwin/amd64 ok uname Darwin LBURmacK1JNJGH8 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64 x86_64 ok go-version go1.19.6 (gc) ok executable /usr/local/bin/chezmoi ok upgrade-method replace-executable ok config-file no config file found ok source-dir ~/.local/share/chezmoi is a git working tree (clean) ok suspicious-entries no suspicious entries 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 info diff-command not set ok edit-command found /usr/bin/vi ok edit-args /usr/bin/vi ok git-command found /usr/local/bin/git, version 2.39.0 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 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 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 vault-command vault not found in $PATH info secret-command not set ```

Additional context

Add any other context about the problem here.

bradenhilton commented 1 year ago

symlink_com.googlecode.iterm2.plist.tmpl and com.googlecode.iterm2.plist will both evaluate to com.googlecode.iterm2.plist. chezmoi is confused here because it sees the ~/.config/iterm2_profile/com.googlecode.iterm2.plist target as both a symlink to a file and a regular file.

You can rename ~/.local/share/chezmoi/dot_config/iterm2_profile/com.googlecode.iterm2.plist to, for example, config.plist, then add it to .chezmoiignore and update the path in the symlink.

https://www.chezmoi.io/user-guide/manage-different-types-of-file/#handle-configuration-files-which-are-externally-modified

devinnasar commented 1 year ago

@bradenhilton So your solution results in both config.plist and com.googlecode.iterm2.plist being rendered to ~/.config/iterm2_profile. My complaint is that .chezmoiignore is not respecting the files added to it.

bradenhilton commented 1 year ago

Your .chezmoiignore isn't matching because it has com.googlecode.iterm2.plist at the root of the target directory.

bradenhilton commented 1 year ago

Actually, now that I look at it more, the rest of the paths in your .chezmoiignore are incorrect.

.chezmoiignore matches target paths, not source paths.

To ignore config.plist, which will be used in the symlink, you need to ignore .config/iterm2_profile/config.plist.

bradenhilton commented 1 year ago

.chezmoiignore:

# -*-mode:gitignore-*- vim:ft=gitignore

# ...

*.gz
LICENSE
README.md
.config/iterm/config.plist

# Ignore non-macOS files.
{{ if ne .chezmoi.os "darwin" -}}
.config/iterm
.Brewfile
{{- end }}

# Ignore non-Windows files.
{{ if ne .chezmoi.os "windows" -}}
.config/windows_terminal
{{- end }}
$ tree .local/share/chezmoi/dot_config/iterm
.local/share/chezmoi/dot_config/iterm
├── config.plist
└── symlink_com.googlecode.iterm2.plist.tmpl
$ tree .config/iterm
.config/iterm
└── com.googlecode.iterm2.plist -> ~/.local/share/chezmoi/dot_config/iterm/config.plist

Please re-open or comment if needed.