chezmoi
chezmoi copied to clipboard
chezmoi add mishandles cases where entry or parent is external
Describe the bug
As reported by @dhruvinsh in #1205, chezmoi add
fails if the path is in a directory implicitly created by an external.
To reproduce
similar to this another issue found, file: .chezmoiexternal.toml
[".oh-my-zsh"] type = "archive" url = "https://github.com/ohmyzsh/ohmyzsh/archive/master.tar.gz" exact = true stripComponents = 1 [".oh-my-zsh/custom/plugins/zsh-syntax-highlighting"] type = "archive" url = "https://github.com/zsh-users/zsh-syntax-highlighting/archive/master.tar.gz" exact = true stripComponents = 1
Everything is working as expect with
chezmoi apply
. But now while my config is managed by chezmoi I decided to add aliases in.oh-my-zsh/custom/aliases.zsh
. and I wanted to track it by chezmoi but when i try to add it by chezmoi I receive below error> ~ chezmoi add .oh-my-zsh/custom/aliases.zsh chezmoi: stat /home/ds/.local/share/chezmoi/https:/github.com/ohmyzsh/ohmyzsh/archive/master.tar.gz: no such file or directory
Expected behavior
chezmoi add
adds the file.
@twpayne I would like to point out something here: Issue #2006 and issue #1574 (this issue) have somewhat similarity but still I believe they are different.
In issue #2006 I had .config/nvim
being managed by .chezmoiexternal
and I was trying to add .config/direnv
(a separate) directory. Thus I was getting error:
chezmoi: mkdir /home/ds/.local/share/chezmoi/dot_config/direnv: no such file or directory
But here in this case, .chezmoiexternal
is managing .oh-my-zsh
and .oh-my-zsh/custom/plugins/zsh-syntax-highlighting
. And when trying to add .oh-my-zsh/custom/aliases.zsh
(same root as one of the .chezmoiexternal) chezmoi give below erro:
chezmoi: stat /home/ds/.local/share/chezmoi/https:/github.com/ohmyzsh/ohmyzsh/archive/master.tar.gz: no such file or directory
I tried few test and it seems that workaround only works if mkdir
error persists. But in case of state
error then workaround does not work and which made me believe that #2006 and this issue are different.
When this issue is fixed, we should also update the docs to include Felipe's neat trick in this comment.
This also applies to files. See https://github.com/twpayne/chezmoi/issues/3559#issuecomment-1951430262.
Adding the workaround reference here, as this issue seems more prominent. Mentioned in https://github.com/twpayne/chezmoi/issues/2006#issuecomment-1099130392
Temporary work around applied:
Manually create a dot_config directory and within that directory touch .keep to force chezmoi to track it.
now using chezmoi add ~/.config/direnv/direnvrc works as expected.
In addition to this you'll need to make your externals exact = false
in the externals toml that conflict. Eg: .chezmoiexternal.toml
[".oh-my-zsh"]
type = "archive"
url = "https://github.com/ohmyzsh/ohmyzsh/archive/master.tar.gz"
exact = false
stripComponents = 1