git_well.repo module

class git_well.repo.Repo(path: str | PathLike[str] | None = None, odbt: Type[LooseObjectDB] = <class 'git.db.GitCmdObjectDB'>, search_parent_directories: bool = False, expand_vars: bool = True)[source]

Bases: Repo

Create a new Repo instance.

Parameters:
  • path

    The path to either the worktree directory or the .git directory itself:

    repo = Repo("/Users/mtrier/Development/git-python")
    repo = Repo("/Users/mtrier/Development/git-python.git")
    repo = Repo("~/Development/git-python.git")
    repo = Repo("$REPOSITORIES/Development/git-python.git")
    repo = Repo(R"C:\Users\mtrier\Development\git-python\.git")
    
    • In Cygwin, path may be a cygdrive/... prefixed path.

    • If path is None or an empty string, GIT_DIR is used. If that environment variable is absent or empty, the current directory is used.

  • odbt – Object DataBase type - a type which is constructed by providing the directory containing the database objects, i.e. .git/objects. It will be used to access all object data.

  • search_parent_directories

    If True, all parent directories will be searched for a valid repo as well.

    Please note that this was the default behaviour in older versions of GitPython, which is considered a bug though.

Raises:
  • git.exc.InvalidGitRepositoryError

  • git.exc.NoSuchPathError

Returns:

Repo

cmd(command: str | list[str], **kwargs: Any) Any[source]

Execute a command in the root of the repo.

property dpath: Path

Alias of working_dir wraped in a ubelt Path

property is_submodule: bool

True if the submodule for another repo.

property config_fpath: Path
classmethod coerce(data: str | PathLike[str] | Repo) Repo[source]

Try to construct a Repo object from input dat

Parameters:

data (str | PathLike | Repo) – If a Repo object, data is returned as-is. If a path inside a git repo, return a Repo object that references the repo root.

Returns:

Repo

classmethod demo() Repo[source]

Create a demo repo for tests

Returns:

Repo

Example

>>> from git_well.repo import Repo
>>> self = Repo.demo()
find_merged_branches(main_branch: str = 'main') Any[source]