find git-dir directly and look up work-tree
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:
-
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.
-
-
Use
git rev-parse --show-toplevelto 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.
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