chezmoi
chezmoi copied to clipboard
Inverse of "overwrite" (i.e. "accept") option for `chezmoi apply`
Is your feature request related to a problem? Please describe.
When running chezmoi apply
and there has been an external modification to a chezmoi-managed file, chezmoi v2.17.2 will prompt what to do with the file:
$ chezmoi apply
.iterm2/com.googlecode.iterm2.plist has changed since chezmoi last wrote it [diff,overwrite,all-overwrite,skip,quit]?
The command reference for "chezmoi apply" doesn't explain which file (the source (chezmoi state) or the target (local state)) gets overwritten when choosing the "overwrite" option, but after testing it I believe it is the target file that gets overwritten from the source.
For files which are most frequently changed externally, i.e. without use of chezmoi edit
(in the example above, the iTerm2 configuration file, which reflects changes the user makes from the app's UI), overwriting the target file is likely to be the opposite of the desired action: it is the source file which should be updated from the target file's state.
From what I understand, users have to chezmoi add
(actually re-add) each file for which they want chezmoi to accept the local state each time it changes. This is cumbersome, especially if there are many of these files.
Describe the solution you'd like
I believe adding "accept"/"all-accept" (or any other sensibly-named) prompts to the output of chezmoi apply
which allows the target file(s) to overwrite the source file(s) when there are conflicts would be a significant QoL improvement.
$ chezmoi apply
.iterm2/com.googlecode.iterm2.plist has changed since chezmoi last wrote it [diff,overwrite,all-overwrite,accept,all-acceptskip,quit]?
(Also, documenting the semantics of each of these prompt options in the command reference for chezmoi apply
would help.)
Describe alternatives you've considered
Instead of adding the "accept (all) local modifications" functionality to chezmoi apply
, this could also be a new command or part of another command.
Additional context
Chances are I'm just misunderstanding how to get chezmoi to accept local changes to managed files, though.
Currently there's chezmoi re-add
which re-adds all modified files where it is possible to do so, but that's not what you're suggesting.
I believe adding "accept"/"all-accept" (or any other sensibly-named) prompts to the output of
chezmoi apply
which allows the target file(s) to overwrite the source file(s) when there are conflicts would be a significant QoL improvement.
This is a very interesting idea, thank you. It's also very hard to implement correctly. The following text assumes familiarity with chezmoi's concepts.
Currently all chezmoi commands either update the destination state (e.g. chezmoi apply
) or they update the source state (e.g. chezmoi add
) but never both. The current implementation of chezmoi assumes that the source state does not change while the destination state is being updated and vice versa. This assumption permits chezmoi to lazily evaluate the target state, which is important for both usability and performance (see the first bullet point of this comment for more details). The proposed accept
and accept-all
would mean that chezmoi apply
would modify both the source and destination states, and since the target state is computed from the source state, this implicitly modifies the target state too, leading to a circular dependency.
In practice some heuristics might help here (I think that accept
and accept-all
would be safe for regular files, but am pretty sure that they're not safe for directories or symbolic links), but this needs more thought.
Would it not be possible to have {all-}accept
simply automate the steps a user would have to take in this situation? i.e.
- Skip
$target(s)
- Remember skipped
$target(s)
- Wait for
chezmoi apply
to finish -
chezmoi add $target(s) [any required options...]
I suppose for that to work there would need to be a mechanism for chezmoi to know when apply
is finished. Does anything like this exist?