Git
Git utilities: branch analysis, operations, status, workflow, validation.
Git utilities for siege_utilities package. Comprehensive git operations, branch management, and status reporting.
- exception siege_utilities.git.GitError[source]
Bases:
SiegeErrorError executing a git command or git workflow operation.
- siege_utilities.git.analyze_branch_status(repo_path='.')[source]
Analyze the current branch status.
- siege_utilities.git.generate_branch_report(output_file=None, repo_path='.', include_commits=20)[source]
Generate a comprehensive branch status report.
- siege_utilities.git.get_commit_history(limit=20, repo_path='.')[source]
Get recent commit history with details.
- siege_utilities.git.get_file_changes(repo_path='.')[source]
Get files that differ from main branch.
- siege_utilities.git.create_feature_branch(branch_name, base_branch='main', repo_path='.', switch_to_branch=True)[source]
Create a new feature branch from base branch.
- siege_utilities.git.switch_branch(branch_name, repo_path='.')[source]
Switch to an existing branch.
SECURITY: Validates branch names to prevent command injection.
- siege_utilities.git.merge_branch(source_branch, target_branch='main', repo_path='.', fast_forward_only=False, squash=False)[source]
Merge a source branch into target branch.
SECURITY: Validates branch names to prevent command injection.
- Parameters:
- Returns:
Dictionary with merge status
- Raises:
GitSecurityError – If branch names fail validation
- Return type:
- siege_utilities.git.rebase_branch(source_branch, base_branch='main', repo_path='.', interactive=False)[source]
Rebase a branch onto another branch.
SECURITY: Validates branch names to prevent command injection.
- siege_utilities.git.stash_changes(message=None, include_untracked=False, repo_path='.')[source]
Stash current changes.
SECURITY: Validates commit message to prevent command injection.
- siege_utilities.git.apply_stash(stash_ref='stash@{0}', repo_path='.', pop=False)[source]
Apply a stashed change.
SECURITY: Validates stash reference to prevent command injection.
- siege_utilities.git.clean_working_directory(repo_path='.', force=False, directories=False, interactive=True)[source]
Clean untracked files from working directory.
- siege_utilities.git.reset_to_commit(commit_hash, reset_type='soft', repo_path='.')[source]
Reset HEAD to a specific commit.
SECURITY: Validates commit hash to prevent command injection.
- siege_utilities.git.cherry_pick_commit(commit_hash, repo_path='.', continue_on_conflict=False)[source]
Cherry-pick a specific commit.
SECURITY: Validates commit hash to prevent command injection.
- siege_utilities.git.create_tag(tag_name, message=None, commit_hash=None, repo_path='.', push=False)[source]
Create a git tag.
SECURITY: This function validates tag names to prevent command injection and invalid git references.
- Parameters:
- Returns:
Dictionary with tag creation status
- Raises:
GitSecurityError – If tag name, message, or commit hash fails validation
- Return type:
Example
>>> result = create_tag("v1.0.0", message="Release 1.0.0") >>> >>> # This will raise GitSecurityError >>> create_tag("<script>alert('xss')</script>") # Invalid tag name
- Security Changes:
Now validates tag names against git ref name rules
Blocks command injection patterns
Validates commit hash format
Validates commit message content
- siege_utilities.git.push_branch(branch_name=None, remote='origin', force=False, repo_path='.')[source]
Push a branch to remote.
SECURITY: Validates branch and remote names to prevent command injection.
- Parameters:
- Returns:
Dictionary with push status
- Raises:
GitSecurityError – If branch or remote name fails validation
- Return type:
- siege_utilities.git.pull_branch(branch_name=None, remote='origin', rebase=False, repo_path='.')[source]
Pull changes from remote branch.
SECURITY: Validates branch and remote names to prevent command injection.
- Parameters:
- Returns:
Dictionary with pull status
- Raises:
GitSecurityError – If branch or remote name fails validation
- Return type:
- siege_utilities.git.get_repository_status(repo_path='.')[source]
Get comprehensive repository status information.
- siege_utilities.git.get_branch_info(repo_path='.')[source]
Get detailed information about all branches.
- siege_utilities.git.get_remote_info(repo_path='.')[source]
Get information about remote repositories.
- siege_utilities.git.get_log_summary(since=None, until=None, author=None, repo_path='.', max_count=100)[source]
Get a summary of commit logs with filtering options.
- siege_utilities.git.start_feature_workflow(feature_name, base_branch='main', repo_path='.', auto_push=True)[source]
Start a new feature development workflow.
- siege_utilities.git.complete_feature_workflow(feature_branch, target_branch='main', repo_path='.', squash=True, delete_branch=True)[source]
Complete a feature development workflow.
- siege_utilities.git.hotfix_workflow(hotfix_name, base_branch='main', repo_path='.', auto_push=True)[source]
Start a hotfix workflow for urgent fixes.
- siege_utilities.git.release_workflow(version, base_branch='main', repo_path='.', auto_push=True)[source]
Start a release workflow for version releases.
- siege_utilities.git.validate_branch_naming(branch_name)[source]
Validate branch naming conventions.
- siege_utilities.git.enforce_commit_conventions(commit_message)[source]
Enforce conventional commit message format.
Submodules
Branch analysis utilities for git repositories. Based on the Change-Agent-AI branch status generator.
- siege_utilities.git.branch_analyzer.analyze_branch_status(repo_path='.')[source]
Analyze the current branch status.
- siege_utilities.git.branch_analyzer.get_commit_history(limit=20, repo_path='.')[source]
Get recent commit history with details.
- siege_utilities.git.branch_analyzer.categorize_commits(commits)[source]
Categorize commits by type and purpose.
- siege_utilities.git.branch_analyzer.get_file_changes(repo_path='.')[source]
Get files that differ from main branch.
- siege_utilities.git.branch_analyzer.get_file_stats(repo_path='.')[source]
Get statistics about file changes.
- siege_utilities.git.branch_analyzer.generate_branch_report(output_file=None, repo_path='.', include_commits=20)[source]
Generate a comprehensive branch status report.
Git operations utilities for repository management. Comprehensive git commands and workflow automation.
- siege_utilities.git.git_operations.create_feature_branch(branch_name, base_branch='main', repo_path='.', switch_to_branch=True)[source]
Create a new feature branch from base branch.
- siege_utilities.git.git_operations.switch_branch(branch_name, repo_path='.')[source]
Switch to an existing branch.
SECURITY: Validates branch names to prevent command injection.
- siege_utilities.git.git_operations.merge_branch(source_branch, target_branch='main', repo_path='.', fast_forward_only=False, squash=False)[source]
Merge a source branch into target branch.
SECURITY: Validates branch names to prevent command injection.
- Parameters:
- Returns:
Dictionary with merge status
- Raises:
GitSecurityError – If branch names fail validation
- Return type:
- siege_utilities.git.git_operations.rebase_branch(source_branch, base_branch='main', repo_path='.', interactive=False)[source]
Rebase a branch onto another branch.
SECURITY: Validates branch names to prevent command injection.
- siege_utilities.git.git_operations.stash_changes(message=None, include_untracked=False, repo_path='.')[source]
Stash current changes.
SECURITY: Validates commit message to prevent command injection.
- siege_utilities.git.git_operations.apply_stash(stash_ref='stash@{0}', repo_path='.', pop=False)[source]
Apply a stashed change.
SECURITY: Validates stash reference to prevent command injection.
- siege_utilities.git.git_operations.clean_working_directory(repo_path='.', force=False, directories=False, interactive=True)[source]
Clean untracked files from working directory.
- siege_utilities.git.git_operations.reset_to_commit(commit_hash, reset_type='soft', repo_path='.')[source]
Reset HEAD to a specific commit.
SECURITY: Validates commit hash to prevent command injection.
- siege_utilities.git.git_operations.cherry_pick_commit(commit_hash, repo_path='.', continue_on_conflict=False)[source]
Cherry-pick a specific commit.
SECURITY: Validates commit hash to prevent command injection.
- siege_utilities.git.git_operations.create_tag(tag_name, message=None, commit_hash=None, repo_path='.', push=False)[source]
Create a git tag.
SECURITY: This function validates tag names to prevent command injection and invalid git references.
- Parameters:
- Returns:
Dictionary with tag creation status
- Raises:
GitSecurityError – If tag name, message, or commit hash fails validation
- Return type:
Example
>>> result = create_tag("v1.0.0", message="Release 1.0.0") >>> >>> # This will raise GitSecurityError >>> create_tag("<script>alert('xss')</script>") # Invalid tag name
- Security Changes:
Now validates tag names against git ref name rules
Blocks command injection patterns
Validates commit hash format
Validates commit message content
- siege_utilities.git.git_operations.push_branch(branch_name=None, remote='origin', force=False, repo_path='.')[source]
Push a branch to remote.
SECURITY: Validates branch and remote names to prevent command injection.
- Parameters:
- Returns:
Dictionary with push status
- Raises:
GitSecurityError – If branch or remote name fails validation
- Return type:
- siege_utilities.git.git_operations.pull_branch(branch_name=None, remote='origin', rebase=False, repo_path='.')[source]
Pull changes from remote branch.
SECURITY: Validates branch and remote names to prevent command injection.
- Parameters:
- Returns:
Dictionary with pull status
- Raises:
GitSecurityError – If branch or remote name fails validation
- Return type:
Git status utilities for repository information and reporting. Comprehensive repository state analysis and monitoring.
- siege_utilities.git.git_status.get_repository_status(repo_path='.')[source]
Get comprehensive repository status information.
- siege_utilities.git.git_status.get_branch_info(repo_path='.')[source]
Get detailed information about all branches.
- siege_utilities.git.git_status.get_remote_info(repo_path='.')[source]
Get information about remote repositories.
- siege_utilities.git.git_status.get_log_summary(since=None, until=None, author=None, repo_path='.', max_count=100)[source]
Get a summary of commit logs with filtering options.
- siege_utilities.git.git_status.get_file_status(repo_path='.')[source]
Get detailed status of all files in the repository.
- siege_utilities.git.git_status.get_repository_size(repo_path='.')[source]
Get repository size information.
Git workflow utilities for automated git operations and best practices. Standardized workflows for feature development, releases, and hotfixes.
- siege_utilities.git.git_workflow.validate_branch_naming(branch_name)[source]
Validate branch naming conventions.
- siege_utilities.git.git_workflow.enforce_commit_conventions(commit_message)[source]
Enforce conventional commit message format.
- siege_utilities.git.git_workflow.start_feature_workflow(feature_name, base_branch='main', repo_path='.', auto_push=True)[source]
Start a new feature development workflow.
- siege_utilities.git.git_workflow.complete_feature_workflow(feature_branch, target_branch='main', repo_path='.', squash=True, delete_branch=True)[source]
Complete a feature development workflow.
- siege_utilities.git.git_workflow.hotfix_workflow(hotfix_name, base_branch='main', repo_path='.', auto_push=True)[source]
Start a hotfix workflow for urgent fixes.
- siege_utilities.git.git_workflow.release_workflow(version, base_branch='main', repo_path='.', auto_push=True)[source]
Start a release workflow for version releases.
- siege_utilities.git.git_workflow.get_workflow_status(repo_path='.')[source]
Get the current workflow status of the repository.
Git input validation and sanitization utilities.
This module provides security-focused input validation for git operations to prevent: - Command injection in git commands - Invalid/malicious branch names, tag names, commit messages - Path traversal in repository paths - Dangerous git command patterns
Use these validators in all git operations to ensure secure command execution.
- exception siege_utilities.git.validation.GitSecurityError[source]
Bases:
ExceptionRaised when git input fails security validation.
- siege_utilities.git.validation.validate_branch_name(branch_name)[source]
Validate a git branch name.
- Parameters:
branch_name (str) – Branch name to validate
- Returns:
Validated branch name
- Raises:
GitSecurityError – If branch name fails validation
- Return type:
Example
>>> validate_branch_name("feature/authentication") 'feature/authentication' >>> validate_branch_name("branch$(cat /etc/passwd)")
- siege_utilities.git.validation.validate_tag_name(tag_name)[source]
Validate a git tag name.
- Parameters:
tag_name (str) – Tag name to validate
- Returns:
Validated tag name
- Raises:
GitSecurityError – If tag name fails validation
- Return type:
Example
>>> validate_tag_name("v1.0.0") 'v1.0.0' >>> validate_tag_name("<script>alert('xss')</script>")
- siege_utilities.git.validation.validate_commit_message(message, max_length=10000)[source]
Validate a git commit message.
- Parameters:
- Returns:
Validated commit message
- Raises:
GitSecurityError – If message fails validation
ValueError – If message is invalid
- Return type:
Example
>>> validate_commit_message("Fix bug in authentication") 'Fix bug in authentication' >>> validate_commit_message("Message; rm -rf /")
- siege_utilities.git.validation.validate_commit_hash(commit_hash)[source]
Validate a git commit hash (SHA).
- Parameters:
commit_hash (str) – Commit hash to validate (short or full)
- Returns:
Validated commit hash
- Raises:
GitSecurityError – If commit hash fails validation
ValueError – If commit hash is invalid
- Return type:
Example
>>> validate_commit_hash("a1b2c3d") 'a1b2c3d' >>> validate_commit_hash("abc123; rm -rf /")
- siege_utilities.git.validation.validate_remote_name(remote_name)[source]
Validate a git remote name.
- Parameters:
remote_name (str) – Remote name to validate (e.g., “origin”)
- Returns:
Validated remote name
- Raises:
GitSecurityError – If remote name fails validation
- Return type:
Example
>>> validate_remote_name("origin") 'origin' >>> validate_remote_name("origin; curl evil.com")
- siege_utilities.git.validation.validate_repo_path(repo_path)[source]
Validate a repository path.
- Parameters:
repo_path (str) – Repository path to validate
- Returns:
Validated Path object
- Raises:
GitSecurityError – If path fails security validation
- Return type:
Example
>>> validate_repo_path(".") >>> validate_repo_path("../../../etc")
- siege_utilities.git.validation.validate_git_ref_name(ref_name, ref_type='ref')[source]
Validate a git reference name (branch, tag, remote).
Implements git-check-ref-format rules: - No path component starting with . - No double dots .. - No ASCII control characters, space, ~, ^, :, ?, *, [ - No ending with / - No ending with .lock - No @ with { following it - No backslashes
- Parameters:
- Returns:
Validated reference name
- Raises:
GitSecurityError – If ref name fails validation
ValueError – If ref name is invalid
- Return type:
Example
>>> validate_git_ref_name("feature/my-branch", "branch") 'feature/my-branch' >>> validate_git_ref_name("branch; rm -rf /", "branch")
- siege_utilities.git.validation.has_dangerous_characters(text)[source]
Check if text contains characters dangerous for git commands.
- Parameters:
text (str) – Text to check
- Returns:
True if text contains dangerous characters
- Return type:
Example
>>> has_dangerous_characters("branch-name") False >>> has_dangerous_characters("branch; rm -rf /") True
Shared internal helpers for the git sub-package.
- siege_utilities.git._utils.run_git_command(*args, repo_path='.', check=True)[source]
Run a git command and return stdout.
When
check=True(default), raisesGitErroron non-zero exit. Whencheck=False, returns""on failure.Note
# SU-1: intentional — check=False callers (upstream detection, # optional config reads, best-effort push/pull) explicitly expect # empty-string as a “not available” sentinel and handle it at the # call site. Do not remove this path without converting all callers # to try/except.