Expand description
Git branch detection for branch-aware strictness.
This module provides reliable detection of the current git branch with fallback mechanisms and per-directory caching for performance.
§Design
- Primary method:
git branch --show-current(most reliable) - Fallback method: Read
.git/HEADfile directly (for environments without git CLI) - Detached HEAD: Returns
Nonefor branch, or commit hash with special marker - Caching: Per working directory cache to avoid repeated subprocess/file reads
§Usage
ⓘ
use destructive_command_guard::git::get_current_branch;
if let Some(branch) = get_current_branch() {
println!("Current branch: {}", branch);
} else {
println!("Not on a branch (detached HEAD or not in git repo)");
}Enums§
- Branch
Info - Result of branch detection.
Functions§
- clear_
cache - Clear the branch cache.
- get_
branch_ info - Get detailed branch information, using cache if available.
- get_
branch_ info_ at_ path - Get branch information for a specific path.
- get_
current_ branch - Get the current git branch, using cache if available.
- is_
in_ git_ repo - Check if the current directory is in a git repository.
- is_
in_ git_ repo_ at_ path - Check if the specified path is in a git repository.