romkatv / gitstatus

Git status for Bash and Zsh prompt
GNU General Public License v3.0
1.65k stars 101 forks source link

Feature request: git repo and working directory options #404

Closed nkh closed 10 months ago

nkh commented 10 months ago

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.

romkatv commented 10 months ago

See docs here: https://github.com/romkatv/gitstatus/blob/38d35b95926e09d07b8cf78edade7cee7a9a1dcf/gitstatus.plugin.zsh#L62-L67

nkh commented 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?

romkatv commented 10 months ago

No. You can give it the directory where .git is and specify worktree in the git config.

nkh commented 10 months ago

to make things more "complex", both directories share the same working tree

that's why git allows: git --git-dir=... --work-tree=...

romkatv commented 10 months ago

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:

  1. Set core.worktree in your git repo. Something like this: git --git-dir=blah config core.worktree blah.
  2. Run export GIT_DIR=blah and observe that gitstatus reports stats from your repo.
nkh commented 10 months ago

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.

romkatv commented 10 months ago

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.

romkatv commented 10 months ago

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.

nkh commented 10 months ago

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.

romkatv commented 10 months ago

Do I understand correctly that you've managed to achieve what you wanted with the existing tools?

nkh commented 10 months ago

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.

screenshot_2023-08-17_21-50-09

romkatv commented 10 months ago

Thanks for the details.