Closed nkh closed 10 months ago
OK, is there a way to give a path to the directory where the git files are (not .git) and the working directory?
No. You can give it the directory where .git
is and specify worktree in the git config.
to make things more "complex", both directories share the same working tree
that's why git allows: git --git-dir=... --work-tree=...
the directory is not called .git
This does not matter.
specifying the work tree in git config is global
This is not true. Try this:
core.worktree
in your git repo. Something like this: git --git-dir=blah config core.worktree blah
.export GIT_DIR=blah
and observe that gitstatus reports stats from your repo.I misunderstood your comment and thought you were referring to the config in $HOME.
What you propose doesn't work in this case because one of the repos is a bare repo and thus the worktree can't be set in the config as core.bare is also set. Note that commands using --git-dir and --work-tree will happily work.
I have a feeling you are dealing with a repo in which you are managing dotfiles. I've seen old articles on the web where they suggest making this repo bare. This isn't necessary. You can simply flip core.bare
to false
and everything will work just as before plus gitstatus will work, too.
The same articles usually will forgo setting core.worktree
and instead pass the workdir on every invocation of git
. This is more cumbersome than necessary.
No, I'm not managing dot file but it was a good guess.
What I'm doing is managing temporary files which are in the work tree of a repo, files one wants to keep under version control because they are more than a line but that are not part of the repo. Of course they could be in the repo but after 10 commit you figure it should never have been in it and now it has to be erased from the repo's history.
I already display the status via gitstatus when I am in the work directory but I'd also like to show the status of the "sub" repo.
Removing core.bare did the trick.
I think it makes sense to keep a bare repo, even if its config says otherwise, since the "sub" repo is not supposed to have files of it own at all.
thank you for the help.
Do I understand correctly that you've managed to achieve what you wanted with the existing tools?
Yes, following your recommendation.
I have a set of commands that make handling the "sub" repo that mirror the main shortcuts I use with git to make things easy.
I call the gitstatus with no argument for the "top" repo then call it again with GIT_DIR set to the "sub" repo and display the status in a different color.
Thanks for the details.
I'd like to show the status of multiple git repos in my prompt and being able to point at what work directory to use to check the status with the repo.
I tried setting GIT_DIR before calling gitstatus_query but it didn't work.