Skip to content

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

Open
abathur wants to merge 1 commit intofboender:masterfrom
abathur:find_git_dir_and_look_up_work_tree
Open

find git-dir directly and look up work-tree#53
abathur wants to merge 1 commit intofboender:masterfrom
abathur:find_git_dir_and_look_up_work_tree

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

tobixen added a commit to tobixen/multi-git-status that referenced this pull request Dec 22, 2025
Add -l/--list FILE option to read repo paths from a file instead of scanning.
Add -s/--save-list FILE option to scan and save repo paths to a file.

The list file supports comments (lines starting with #) and empty lines.

Based on PR fboender#27 by cipherbrain, adapted to work with the find_git_work_tree
approach from PR fboender#53.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tobixen added a commit to tobixen/multi-git-status that referenced this pull request Dec 22, 2025
Document which pull requests have been integrated into this fork:
- PR fboender#62: reftable refs format support
- PR fboender#61: make uninstall target
- PR fboender#53: improved git-dir detection
- PR fboender#51: FHS-compliant man page path
- PR fboender#27: list file support

Updated usage section with new options (-b, -l, -s, -h).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
rymdbar pushed a commit to rymdbar/multi-git-status that referenced this pull request Feb 14, 2026
Pull-request fboender#53 broke `--no-depth`. When searching for GIT_DIR (.git)
rather than parent PROJ_DIR (actual repo), the max-depth clearly also
needs to be increased.
@rymdbar
Copy link

rymdbar commented Feb 14, 2026

This pull-request needs to also use a higher maxdepth for --no-depth. It completely breaks that functionality in its current form.

diff --git a/mgitstatus b/mgitstatus                                                                                                                                          
index 41636bc..b803a78 100755                                                                                                                                                 
--- a/mgitstatus                                                                                                                                                              
+++ b/mgitstatus                                                                                                                                                              
@@ -322,7 +322,7 @@ if [ "$NO_DEPTH" -eq 1 ]; then                                                                                                                            
     # Do not recurse at all. Really, this should have been the '-d 0' option, 
     # but that's already used for infinite recursion, and we don't want to
     # break backwards compatibility.
-    FIND_OPTS="$FIND_OPTS -maxdepth 0"                                                                                                                                       
+    FIND_OPTS="$FIND_OPTS -maxdepth 1"                                                                                                                                       
 fi

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?

2 participants

Comments