class documentation

A git repository backed by local disk.

To open an existing repository, call the constructor with the path of the repository.

To create a new repository, use the Repo.init class method.

Note that a repository object may hold on to resources such as file handles for performance reasons; call .close() to free up those resources.

Class Method discover Iterate parent directories to discover a repository.
Class Method init Create a new repository.
Class Method init_bare Create a new bare repository.
Method __enter__ Enter context manager.
Method __exit__ Exit context manager and close repository.
Method __init__ Open a repository on disk.
Method __repr__ Return string representation of this repository.
Method clone Clone this repository.
Method close Close any files opened by this repository.
Method commondir Return the path of the common directory.
Method controldir Return the path of the control directory.
Method get_blob_normalizer Return a BlobNormalizer object.
Method get_config Retrieve the config object.
Method get_description Retrieve the description of this repository.
Method get_gitattributes Read gitattributes for the repository.
Method get_named_file Get a file from the control dir with a specific name.
Method get_rebase_state_manager Get the appropriate rebase state manager for this repository.
Method get_worktree Get the working tree for this repository.
Method get_worktree_config Get the worktree-specific config.
Method has_index Check if an index is present.
Method index_path Return path to the index file.
Method open_index Open the index for this repository.
Method read_reflog Read reflog entries for a reference.
Method set_description Set the description for this repository.
Instance Variable bare Whether this is a bare repository
Instance Variable filter_context Undocumented
Instance Variable object_format Undocumented
Instance Variable object_store Undocumented
Instance Variable path Path to the working copy (if it exists) or repository control directory (if the repository is bare)
Instance Variable refs Undocumented
Instance Variable worktrees Undocumented
Class Method _init_maybe_bare Undocumented
Class Method _init_new_working_directory Create a new working directory linked to a repository.
Method _del_named_file Delete a file in the control directory with the given name.
Method _determine_file_mode Probe the file-system to determine whether permissions can be trusted.
Method _determine_symlinks Probe the filesystem to determine whether symlinks can be created.
Method _get_config_condition_matchers Get condition matchers for includeIf conditions.
Method _get_shared_repository_permissions Get shared repository file and directory permissions from config.
Method _put_named_file Write a file to the control dir with the given name and contents.
Method _read_gitattributes Read .gitattributes file from working tree.
Method _reflog_path Undocumented
Method _write_reflog Undocumented
Instance Variable _commondir Undocumented
Instance Variable _controldir Undocumented
Instance Variable _graftpoints Undocumented

Inherited from BaseRepo:

Method __contains__ Check if a specific Git object or ref is present.
Method __delitem__ Remove a ref.
Method __getitem__ Retrieve a Git object by SHA1 or ref.
Method __setitem__ Set a ref.
Method fetch Fetch objects into another repository.
Method fetch_pack_data Fetch the pack data required for a set of revisions.
Method find_missing_objects Fetch the missing objects required for a set of revisions.
Method generate_pack_data Generate pack data objects for a set of wants/haves.
Method get_config_stack Return a config stack for this repository.
Method get_graph_walker Retrieve a graph walker.
Method get_object Retrieve the object with the specified SHA.
Method get_parents Retrieve the parents of a specific commit.
Method get_peeled Get the peeled value of a ref.
Method get_refs Get dictionary with all refs.
Method get_shallow Get the set of shallow commits.
Method get_walker Obtain a walker for this repository.
Method head Return the SHA1 pointed at by HEAD.
Method parents_provider Get a parents provider for this repository.
Method update_shallow Update the list of shallow objects.
Instance Variable hooks Undocumented
Property notes Access notes functionality for this repository.
Method _add_graftpoints Add or modify graftpoints.
Method _change_object_format Change the object format of this repository.
Method _get_object Undocumented
Method _get_user_identity Determine the identity to use for new commits.
Method _init_config Initialize repository configuration.
Method _init_files Initialize a default set of named files.
Method _read_heads Undocumented
Method _remove_graftpoints Remove graftpoints.
def discover(cls, start: str | bytes | os.PathLike[str] = '.') -> Repo:

Iterate parent directories to discover a repository.

Return a Repo object for the first parent directory that looks like a Git repository.

Parameters
start:str | bytes | os.PathLike[str]The directory to start discovery from (defaults to '.')
Returns
RepoUndocumented
def init(cls, path: str | bytes | os.PathLike[str], *, mkdir: bool = False, config: StackedConfig | None = None, default_branch: bytes | None = None, symlinks: bool | None = None, format: int | None = None, shared_repository: str | bool | None = None, object_format: str | None = None) -> Repo:

Create a new repository.

Returns: Repo instance

Parameters
path:str | bytes | os.PathLike[str]Path in which to create the repository
mkdir:boolWhether to create the directory
config:StackedConfig | NoneConfiguration object
default_branch:bytes | NoneDefault branch name
symlinks:bool | NoneWhether to support symlinks
format:int | NoneRepository format version (defaults to 0)
shared_repository:str | bool | NoneShared repository setting (group, all, umask, or octal)
object_format:str | NoneObject format to use ("sha1" or "sha256", defaults to "sha1")
Returns
RepoUndocumented
def init_bare(cls, path: str | bytes | os.PathLike[str], *, mkdir: bool = False, object_store: PackBasedObjectStore | None = None, config: StackedConfig | None = None, default_branch: bytes | None = None, format: int | None = None, shared_repository: str | bool | None = None, object_format: str | None = None) -> Repo:

Create a new bare repository.

path should already exist and be an empty directory.

Returns: a Repo instance

Parameters
path:str | bytes | os.PathLike[str]Path to create bare repository in
mkdir:boolWhether to create the directory
object_store:PackBasedObjectStore | NoneObject store to use
config:StackedConfig | NoneConfiguration object
default_branch:bytes | NoneDefault branch name
format:int | NoneRepository format version (defaults to 0)
shared_repository:str | bool | NoneShared repository setting (group, all, umask, or octal)
object_format:str | NoneObject format to use ("sha1" or "sha256", defaults to "sha1")
Returns
RepoUndocumented
def __enter__(self) -> Repo:

Enter context manager.

def __exit__(self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None):

Exit context manager and close repository.

def __init__(self, root: str | bytes | os.PathLike[str], object_store: PackBasedObjectStore | None = None, bare: bool | None = None):

Open a repository on disk.

Parameters
root:str | bytes | os.PathLike[str]Path to the repository's root.
object_store:PackBasedObjectStore | NoneObjectStore to use; if omitted, we use the repository's default object store
bare:bool | NoneTrue if this is a bare repository.
def __repr__(self) -> str:

Return string representation of this repository.

def clone(self, target_path: str | bytes | os.PathLike[str], *, mkdir: bool = True, bare: bool = False, origin: bytes = b'origin', checkout: bool | None = None, branch: bytes | None = None, progress: Callable[[str], None] | None = None, depth: int | None = None, symlinks: bool | None = None) -> Repo:

Clone this repository.

Returns: Created repository as Repo

Parameters
target_path:str | bytes | os.PathLike[str]Target path
mkdir:boolCreate the target directory
bare:boolWhether to create a bare repository
origin:bytesBase name for refs in target repository cloned from this repository
checkout:bool | NoneWhether or not to check-out HEAD after cloning
branch:bytes | NoneOptional branch or tag to be used as HEAD in the new repository instead of this repository's HEAD.
progress:Callable[[str], None] | NoneOptional progress function
depth:int | NoneDepth at which to fetch
symlinks:bool | NoneSymlinks setting (default to autodetect)
Returns
RepoUndocumented
def close(self):

Close any files opened by this repository.

def commondir(self) -> str:

Return the path of the common directory.

For a main working tree, it is identical to controldir().

For a linked working tree, it is the control directory of the main working tree.

def controldir(self) -> str:

Return the path of the control directory.

def get_blob_normalizer(self) -> FilterBlobNormalizer:

Return a BlobNormalizer object.

def get_config(self) -> ConfigFile:

Retrieve the config object.

Returns: ConfigFile object for the .git/config file.

def get_description(self) -> bytes | None:

Retrieve the description of this repository.

Returns: Description as bytes or None.

def get_gitattributes(self, tree: bytes | None = None) -> GitAttributes:

Read gitattributes for the repository.

Parameters
tree:bytes | NoneTree SHA to read .gitattributes from (defaults to HEAD)
Returns
GitAttributesGitAttributes object that can be used to match paths
def get_named_file(self, path: str | bytes, basedir: str | None = None) -> BinaryIO | None:

Get a file from the control dir with a specific name.

Although the filename should be interpreted as a filename relative to the control dir in a disk-based Repo, the object returned need not be pointing to a file in that location.

Returns: An open file object, or None if the file does not exist.

Parameters
path:str | bytesThe path to the file, relative to the control dir.
basedir:str | NoneOptional argument that specifies an alternative to the control dir.
Returns
BinaryIO | NoneUndocumented
def get_rebase_state_manager(self) -> RebaseStateManager:

Get the appropriate rebase state manager for this repository.

Returns: DiskRebaseStateManager instance

def get_worktree(self) -> WorkTree:

Get the working tree for this repository.

Returns
WorkTreeWorkTree instance for performing working tree operations
def get_worktree_config(self) -> ConfigFile:

Get the worktree-specific config.

Returns
ConfigFileConfigFile object for the worktree config
def has_index(self) -> bool:

Check if an index is present.

def index_path(self) -> str:

Return path to the index file.

def open_index(self) -> Index:

Open the index for this repository.

Returns: The matching Index

Raises
NoIndexPresentIf no index is present
def read_reflog(self, ref: bytes) -> Generator[reflog.Entry, None, None]:

Read reflog entries for a reference.

Parameters
ref:bytesReference name (e.g. b'HEAD', b'refs/heads/master')
Returns
Generator[reflog.Entry, None, None]Undocumented
Yields
reflog.Entry objects in chronological order (oldest first)
def set_description(self, description: bytes):

Set the description for this repository.

Parameters
description:bytesText to set as description for this repository.
bare: bool =

Whether this is a bare repository

filter_context: FilterContext | None =

Undocumented

object_format =

Undocumented

object_store: DiskObjectStore =

Undocumented

path: str =

Path to the working copy (if it exists) or repository control directory (if the repository is bare)

refs =

Undocumented

worktrees =

Undocumented

def _init_maybe_bare(cls, path: str | bytes | os.PathLike[str], controldir: str | bytes | os.PathLike[str], bare: bool, object_store: PackBasedObjectStore | None = None, config: StackedConfig | None = None, default_branch: bytes | None = None, symlinks: bool | None = None, format: int | None = None, shared_repository: str | bool | None = None, object_format: str | None = None) -> Repo:

Undocumented

def _init_new_working_directory(cls, path: str | bytes | os.PathLike[str], main_repo: Repo, identifier: str | None = None, mkdir: bool = False, relative_paths: bool = False) -> Repo:

Create a new working directory linked to a repository.

Returns: Repo instance

Parameters
path:str | bytes | os.PathLike[str]Path in which to create the working tree.
main_repo:RepoMain repository to reference
identifier:str | NoneWorktree identifier
mkdir:boolWhether to create the directory
relative_paths:boolWhether to use relative paths for gitdir references
Returns
RepoUndocumented
def _del_named_file(self, path: str):

Delete a file in the control directory with the given name.

def _determine_file_mode(self) -> bool:

Probe the file-system to determine whether permissions can be trusted.

Returns: True if permissions can be trusted, False otherwise.

def _determine_symlinks(self) -> bool:

Probe the filesystem to determine whether symlinks can be created.

Returns: True if symlinks can be created, False otherwise.

def _get_config_condition_matchers(self) -> dict[str, ConditionMatcher]:

Get condition matchers for includeIf conditions.

Returns a dict of condition prefix to matcher function.

def _get_shared_repository_permissions(self) -> tuple[int | None, int | None]:

Get shared repository file and directory permissions from config.

Returns
tuple[int | None, int | None]tuple of (file_mask, directory_mask) or (None, None) if not shared
def _put_named_file(self, path: str, contents: bytes):

Write a file to the control dir with the given name and contents.

Parameters
path:strThe path to the file, relative to the control dir.
contents:bytesA string to write to the file.
def _read_gitattributes(self) -> dict[bytes, dict[bytes, bytes]]:

Read .gitattributes file from working tree.

Returns
dict[bytes, dict[bytes, bytes]]Dictionary mapping file patterns to attributes
def _reflog_path(self, ref: bytes) -> str:

Undocumented

def _write_reflog(self, ref: bytes, old_sha: bytes, new_sha: bytes, committer: bytes | None, timestamp: int | None, timezone: int | None, message: bytes):

Undocumented

_commondir =

Undocumented

_controldir =

Undocumented

_graftpoints: dict =

Undocumented