Skip to content

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>
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