Module git

Module git 

Source
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

CommandDescription
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 pullPull (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

  1. Chained commands - Simple split on delimiters; doesn’t handle quoted delimiters

Structs§

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