multi-git-status icon indicating copy to clipboard operation
multi-git-status copied to clipboard

find git-dir directly and look up work-tree

Open abathur opened this issue 2 years ago • 1 comments

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.

abathur avatar Dec 25 '22 03:12 abathur

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

abathur avatar Dec 25 '22 03:12 abathur