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

Support a root directory other than the repository's root #891

Closed
felipecrs opened this issue Sep 24, 2020 · 12 comments · Fixed by #1459
Closed

Support a root directory other than the repository's root #891

felipecrs opened this issue Sep 24, 2020 · 12 comments · Fixed by #1459
Labels
enhancement New feature or request

Comments

@felipecrs
Copy link
Contributor

felipecrs commented Sep 24, 2020

The problem

I use my dotfiles repository extensively, not only for dotfiles, but other things that relates to my machines management. Despite chezmoi supports ignoring files through the .chezmoiignore, I would like to sort my repository by moving all my real dotfiles to a folder called home in the repository (just like homeshick), so I would not need to manage the .chezmoiignore anymore.

Solution

A way to set the default root for the source dotfiles, other than the repository root. Probably a new key in the .chezmoi.toml.tmpl

Alternatives

I though on setting sourceFolder to the sub-folder that I want, but I wonder if this won't break any other chezmoi functionality such as chezmoi update since the sourceFolder would not be the git root anymore.

@felipecrs felipecrs added the enhancement New feature or request label Sep 24, 2020
@twpayne
Copy link
Owner

twpayne commented Sep 24, 2020

Would it work to put all your non-home directory stuff in a directory called stuff and then add stuff to .chezmoiignore?

@felipecrs
Copy link
Contributor Author

Unfortunately not, many of the files that I'm referring to are supposed to stay in the repository root. Such as:

README.md
LICENSE
install # Installer for Codespaces
.gitpod.*
.vscode/
.devcontainer/

https://github.com/felipecrs/dotfiles/blob/master/.chezmoiignore

@felipecrs
Copy link
Contributor Author

felipecrs commented Sep 24, 2020

This would also help newcomers from homeshick and homesick to migrate. :)

@explorador
Copy link

I actually tried setting the sourceFolder to a sub-directory and it works fine for me, even chezmoi update

felipecrs added a commit to felipecrs/dotfiles that referenced this issue Sep 18, 2021
This moves all files which are actually mapped to the home folder with chezmoi to a subfolder of the repository called home.

This gives me peace of mind for adding more files to the repo without worrying about polluting my actual home folder. This way, things are much more organized.

This also includes a migration script, so users who still are using the old TOML format for configuration, or have their chezmoi not pointing to the home subfolder will be prompted for fixing it by reinitializing chezmoi. The migration also handles the deletion of old configuration. Deleting the whole configuration is needed because of twpayne/chezmoi#1431.

References twpayne/chezmoi#891
@felipecrs
Copy link
Contributor Author

Ok, so I implemented your suggestion, @explorador at felipecrs/dotfiles#32. It's working so far.

@twpayne:

The only issue that I can think of is with chezmoi init for initially installing the dotfiles. The current syntax does not seem to support using a subfolder of the git repo:

https://www.chezmoi.io/docs/reference/#init-repo

@felipecrs
Copy link
Contributor Author

felipecrs commented Sep 18, 2021

Actually, there is a major issue with this approach:

Every time I call chezmoi init, chezmoi creates the ~/.dotfiles/home/.git folder. Ideally, chezmoi should detect that its home folder is already in a git project.

Because of this, chezmoi update does not work. If I remove the folder manually, chezmoi update starts to work again.

I implemented a workaround at felipecrs/dotfiles@e642eb9.

@felipecrs
Copy link
Contributor Author

Moving from #1423 (comment).

@twpayne I can try to propose a PR to fix it but unfortunately not today, most likely tomorrow. Please don't wait for me if you are willing to try my suggestion, as it should be very simple anyway.

@felipecrs
Copy link
Contributor Author

felipecrs commented Sep 23, 2021

With 2.5.0, #891 (comment) was fixed. 🎉

Another point that I noted, was that chezmoi edit opens my subfolder instead of the repository. This is for sure expected, but when not using the root of the git repository as root for chezmoi, the problem is that when I open the subfolder in VS Code, VS Code won't load my repository settings at the root of the repo, making everything a mess (at least for me).

Some workarounds that I can think of:

@felipecrs
Copy link
Contributor Author

@twpayne the only missing thing from my perspective is #891 (comment).

@twpayne
Copy link
Owner

twpayne commented Sep 28, 2021

Thanks, re-opening.

@twpayne twpayne reopened this Sep 28, 2021
@twpayne
Copy link
Owner

twpayne commented Oct 4, 2021

The only issue that I can think of is with chezmoi init for initially installing the dotfiles. The current syntax does not seem to support using a subfolder of the git repo:

This can now be done using the -W/--working-tree and -S/--source flags:

$ chezmoi init --working-tree=~/.local/share/chezmoi --source=~/.local/share/chezmoi/home

80efab9 added a test for this (search for workingtree.txt).

Hopefully this is now all done - please reopen if needed.

@twpayne twpayne closed this as completed Oct 4, 2021
@felipecrs
Copy link
Contributor Author

felipecrs commented Oct 4, 2021

Cool, it indeed works:

$ docker run --rm -it buildpack-deps:curl bash
$ bash <(curl -fsSL https://git.io/chezmoi) -- init --working-tree=~/.dotfiles --source=~/.dotfiles/home felipecrs

Thank you very much!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants