twpayne / chezmoi

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

chezmoiexternal with subdir config inconsistent state #3131

Closed qcu266 closed 1 year ago

qcu266 commented 1 year ago

What exactly are you trying to do?

I used neovim nvchad, however nvchad custom config script should in subdir lua/custom.

so, I want to use .chezmoiexternal.toml to manager nvchad offical repo code , and to use dot_config/nvim/lua/custom to manager myself config.

However, I got inconsistent state error:

$ chezmoi apply
chezmoi: .config/nvim: inconsistent state (/Users/qcu/.local/share/chezmoi/dot_config/nvim, https://github.com/NvChad/NvChad defined in /Users/qcu/.local/share/chezmoi/.chezmoiexternal.toml)

How to configure this scenario?

What have you tried so far?

Describe what you have tried so far.

Where else have you checked for solutions?

halostatue commented 1 year ago

3065 and #2015 appear to be related to what you’re reporting. You may want to skim those to see if any of the solutions there suggest themselves for this issue.

If they do not, please include your .chezmoiexternal configuration and the output of chezmoi doctor as well as any other information you discover while looking over those.

qcu266 commented 1 year ago

@halostatue Thank you very much for the assistance you provided,I found a solution in #3065

However, I also encountered some confusing aspects. I'm not sure if it's a bug or intentionally designed this way.

The following configuration should work:

# with chezmoi add exact dir:  `dot_config/exact_nvim/exact_lua/exact_custom`
[".config/nvim"]
    type = "archive"
    url = "https://github.com/NvChad/NvChad/archive/refs/heads/v2.0.tar.gz"
    exact = true
    stripComponents = 1
    refreshPeriod = "168h"

However, the configuration below will result in the same “inconsistent state” error:

# with chezmoi add exact dir:  `dot_config/exact_nvim/exact_lua/exact_custom`
[".config/nvim"]
    type = "git-repo"
    url = "https://github.com/NvChad/NvChad"
    exact = true
    stripComponents = 1
    clone.args = ["--branch", "v2.0", "--depth", "1"]
    pull.args = ["--ff-only"]
    refreshPeriod = "168h"
halostatue commented 1 year ago

I’m glad you found at least a partial solution here, but as I am not using externals in this way, I am the wrong person to answer those questions. Hopefully someone else will be able to chime in on this.

twpayne commented 1 year ago

tl;dr if you want to add your own files to an external directory, use type = "archive".

However, I also encountered some confusing aspects. I'm not sure if it's a bug or intentionally designed this way.

I agree that this is confusing. There are good design reasons behind the decision. What's happening is:

When the external type = "archive", then chezmoi downloads the archive and gets a full, precise view of the state of every file. This means that chezmoi can merge this state with its own state (e.g. the extra dot_config/nvim/lua/custom file) and get a consistent view of what you want in your home directory.

When the external type = "git-repo", then chezmoi delegates management of that directory to git. git is a large, complex application with many subtleties, and chezmoi cannot hope to follow git's behavior exactly. So, chezmoi does not attempt to merge its state, which is why you get the "inconsistent state" error.

So, your use of type = "archive" is the right approach here.