Skip to main content

Module git

Module git 

Source
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/HEAD file directly (for environments without git CLI)
  • Detached HEAD: Returns None for 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§

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