CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-gitpython

GitPython is a Python library used to interact with Git repositories

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

exceptions.mddocs/

Exception Handling

Comprehensive exception hierarchy for robust error handling across all Git operations. Includes specific exceptions for common Git scenarios and command failures.

Capabilities

Base Exceptions

class GitError(Exception):
    """Base exception for all git operations."""

class InvalidGitRepositoryError(GitError):
    """Repository is not a valid git repository."""

class WorkTreeRepositoryUnsupported(GitError):
    """Operation not supported on worktree repositories."""

class NoSuchPathError(GitError):
    """Path does not exist in repository."""

Command Exceptions

class CommandError(GitError):
    """Git command execution failed."""

class GitCommandError(CommandError):
    """Git command returned non-zero exit code."""
    
    @property
    def status(self) -> int:
        """Command exit status."""
    
    @property
    def command(self) -> list[str]:
        """Failed command."""
    
    @property
    def stdout(self) -> str:
        """Command stdout."""
    
    @property
    def stderr(self) -> str:
        """Command stderr."""

class GitCommandNotFound(CommandError):
    """Git executable not found."""

Security Exceptions

class UnsafeProtocolError(GitError):
    """Unsafe protocol usage detected."""

class UnsafeOptionError(GitError):
    """Unsafe option usage detected."""

Repository State Exceptions

class CheckoutError(GitError):
    """Checkout operation failed."""

class RepositoryDirtyError(GitError):
    """Repository has uncommitted changes."""

class UnmergedEntriesError(GitError):
    """Index contains unmerged entries."""

class CacheError(GitError):
    """Object cache operation failed."""

class HookExecutionError(GitError):
    """Git hook execution failed."""

Object Database Exceptions

# Inherited from gitdb
class AmbiguousObjectName(GitError):
    """Object name matches multiple objects."""

class BadName(GitError):
    """Invalid object name."""

class BadObject(GitError):
    """Invalid or corrupted object."""

class BadObjectType(GitError):
    """Invalid object type."""

class InvalidDBRoot(GitError):
    """Invalid database root directory."""

class ODBError(GitError):
    """Object database error."""

class ParseError(GitError):
    """Object parsing failed."""

class UnsupportedOperation(GitError):
    """Operation not supported."""

Usage Examples

from git import Repo, GitCommandError, InvalidGitRepositoryError

try:
    repo = Repo('/invalid/path')
except InvalidGitRepositoryError as e:
    print(f"Not a git repository: {e}")

try:
    repo = Repo('/valid/repo')
    repo.git.execute(['invalid-command'])
except GitCommandError as e:
    print(f"Command failed: {e.command}")
    print(f"Exit code: {e.status}")
    print(f"Error: {e.stderr}")

# Handle specific scenarios
try:
    repo.heads.main.checkout()
except CheckoutError as e:
    print(f"Checkout failed: {e}")
    # Handle conflicts or dirty working tree

try:
    repo.index.commit("Test commit")
except RepositoryDirtyError:
    print("Cannot commit: repository has uncommitted changes")

docs

command.md

configuration.md

database.md

diff.md

exceptions.md

index-staging.md

index.md

objects.md

references.md

remote.md

repository.md

tile.json