Expand description
Git branch tracking utilities for mi6.
This module provides functionality to:
- Capture the current git branch from a working directory
- Parse branch names to extract PR/issue numbers
- Detect git branch-changing commands in shell commands
§Branch Name Parsing
The parse_branch_info function extracts issue and PR numbers from branch names
using common naming conventions.
§PR Number Patterns
| Pattern | Example | Extracted |
|---|---|---|
pr-N | pr-100 | pr: 100 |
prN | feature/pr200 | pr: 200 |
§Issue Number Patterns (in priority order)
| Pattern | Example | Extracted |
|---|---|---|
issue-N | feature/issue-123 | issue: 123 |
issueN | feature/issue456 | issue: 456 |
gh-N | fix/GH-456 | issue: 456 |
fix-N | fix-789-description | issue: 789 |
| Leading number | 123-add-feature | issue: 123 |
| Trailing number | feature-something-42 | issue: 42 |
Notes:
- Matching is case-insensitive
- Only the last path component after
/is parsed (e.g.,feature/issue-123parsesissue-123) - PR patterns are checked before issue patterns
- First matching pattern wins
- Branches like
fix/123work via the “leading number” pattern (thefix/prefix is stripped when extracting the last component)
§Examples
main -> (no extraction)
feature/issue-123 -> issue: 123
fix/GH-456 -> issue: 456
pr-100 -> pr: 100
feature/pr-200 -> pr: 200
fix-789-description -> issue: 789
fix/123-some-bug -> issue: 123 (via leading number)
123-add-feature -> issue: 123
feature-add-something-42 -> issue: 42
feature/add-new-thing -> (no extraction)§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
- Branch parsing is heuristic - May not match all naming conventions
- 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 - Parse a branch name to extract PR and issue numbers.
- parse_
github_ repo_ from_ remote_ url - Parse GitHub repo from a git remote URL.