Expand description
Git branch tracking utilities for mi6.
This module provides functionality to:
- Capture the current git branch from a working directory
- Detect git branch-changing commands in shell commands
§Branch Info Capture
The parse_branch_info function captures the git branch name.
Note: This function does not extract issue/PR numbers from branch names.
Branch naming conventions are too inconsistent and led to false positives
(e.g., upgrade-text-fix-2 being incorrectly parsed as issue #2).
Issue and PR numbers are now only extracted from explicit gh CLI commands
(see the github module).
§Branch-Changing Command Detection
The is_branch_changing_command function detects git commands that change the
current branch, triggering re-capture of branch info.
§Detected Commands
| Command | Description |
|---|---|
git checkout <branch> | Switch branches |
git checkout -b <branch> | Create and switch |
git switch <branch> | Modern branch switch |
git worktree add <path> | Create worktree |
git merge <branch> | Merge (may fast-forward) |
git rebase <branch> | Rebase onto branch |
git pull | Pull (may merge/rebase) |
§Chained Command Support
Commands are split on &, |, and ; to detect branch changes in compound commands:
echo foo && git checkout main -> detected
git status; git checkout main -> detected
cargo build && git switch dev -> detected§Limitations
- Chained commands - Simple split on delimiters; doesn’t handle quoted delimiters
Structs§
- GitBranch
Info - Result of parsing a git branch name for PR/issue numbers.
Functions§
- get_
branch_ info - Get git branch info for a directory.
- get_
current_ branch - Get the current git branch for a directory.
- get_
github_ repo - Get the GitHub repository from git remote origin.
- get_
local_ git_ dir - Get the absolute path to the .git directory for a working directory.
- get_
worktree_ root - Get the worktree root path if the current directory is within a git worktree.
- is_
branch_ changing_ command - Check if a shell command might change the git branch.
- parse_
branch_ info - Create a GitBranchInfo from a branch name.
- parse_
github_ repo_ from_ remote_ url - Parse GitHub repo from a git remote URL.