find git-dir directly and look up work-tree #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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-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.