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

find git-dir directly and look up work-tree #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

abathur
Copy link

@abathur abathur commented Dec 25, 2022

This enables mgitstatus to handle repositories with non-standard work tree locations (such as those used by yadm) and would close #26. It can discover these within the directory tree, or the user can use positional args to explicitly list the path to the git-dir.

Two broad strokes to this:

  1. Instead of checking every sub-directory for a .git directory in the standard location, search directly for directories matching "*.git".

    • Since standard .git directories will be one level deeper in the tree, this adds 1 to DEPTH.

    • Since we're looking for the .git directory itself, I think we can use -prune to skip searching within those matching directories.

  2. Use git rev-parse --show-toplevel to look up the work tree. As far as I can tell, this will report the path of a non-standard work tree. This will error (and print nothing) on a standard repo. If that fails to produce output, fall back on the existing guess that the work tree will be the parent directory of the git-dir.

    Most of the diff is from computing this once (as PROJ_DIR) and replacing instances of $(dirname "$GIT_DIR") with it.

This enables mgitstatus to handle repositories with non-standard work
tree locations (such as those used by yadm). It can discover these, or
the user can explicitly list the path to the git-dir.

Two broad strokes to this:

1. Instead of checking every sub-directory for a .git directory in the
   standard location, search directly for directories matching "*.git".

   - Since *standard* .git directories will be one level deeper in the
     tree, this adds 1 to DEPTH.

   - Since we're looking for the .git directory itself, I think we can
     use -prune to skip searching within those matching directories.

2. Use `git rev-parse --show-toplevel` to look up the work tree. As
   far as I can tell, this will report the path of a non-standard
   work tree. This will error (and print nothing) on a standard repo.
   If that fails to produce output, fall back on the existing guess
   that the work tree will be the parent directory of the git-dir.

   Most of the diff is from computing this once (as PROJ_DIR) and
   replacing instances of `$(dirname "$GIT_DIR")` with it.
@abathur
Copy link
Author

abathur commented Dec 25, 2022

Aside: If it helps anyone, I have this packaged as a Nix flake for my own use at https://github.com/abathur/multi-git-status/tree/lookup_worktree_flake

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

Successfully merging this pull request may close these issues.

targeting git repos with a nonstandard name/path?
1 participant