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

Do not list empty directories and directories with only ignored files/subdirectories in unmanaged output #3608

Open
xduugu opened this issue Feb 28, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@xduugu
Copy link

xduugu commented Feb 28, 2024

Is your feature request related to a problem? Please describe.

chezmoi unmanaged inlcudes empty directories and directories with only ignored files or subdirectories in its output. This makes it harder to tell if there are files left that should be added to chezmoi.

For example, the directory ~/.config/dconf usually only contains a single file, user, but if I add an ignore entry to chezmoiignore

.config/dconf/user

chezmoi unmanaged still lists .config/dconf as unmanaged.

Describe the solution you'd like

chezmoi unmanaged should not include these "empty" directories in its output.

Describe alternatives you've considered

It is possible to ignore the whole directory, for example,

.config/dconf

but in this case, I would not notice if dconf adds another file to its directory that I might want to add to chezmoi.

@xduugu xduugu added the enhancement New feature or request label Feb 28, 2024
@halostatue
Copy link
Collaborator

I think that this would be worthwhile, but it will take some time to consider how to approach the solution.

Chezmoi uses twpayne/go-vfs, which is modelled after Go's own path.fs.Walk, which processes each directory entry in turn, and if the entry is itself a directory entry, processes the children of the directory. The processing is a closure passed to the Walk function. There is only an error value returned from child records.

This approach is very simple to implement, but means that:

  • .config/dconf is printed during the unmanaged function before it knows anything about the contents of .config/dconf.
  • There is no error response which indicates "directory is empty".

The former could be fixed by visiting the children of directories first, but the second prevents that from being useful — and it has the unintuitive result of making the output look like:

.config/git/unmanaged
.config/git

instead of the somewhat more intuitive

.config/git
.config/git/unmanaged

Because chezmoi keeps state about what it does know about, there is probably something that could be done, but it's not clear to me exactly what could be done (I'm not that familiar with how those parts of chezmoi interact…yet).

@mbhutton
Copy link

The workaround I'm using is to add an effectively empty directory to the source state.

Eg to avoid having chezmoi unmanaged list .config/dconf when there's already an ignore for .config/dconf/user, you can add an empty directory dot_config/dconf to the source state.

Because git doesn't really see empty directories, you can also add an empty file eg .config/dconf/.nothing to make the directory trackable in git.

With this approach, .config/dconf won't be listed unless a new file/dir is added.

This solves the problem for me. If it also solves it from OP's POV, perhaps just a documentation change is needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants