nicetoolbox.utils.git_utils

Helper functions for git integration of the code

Classes

CustomRepo

Customize the Repo class from gitpython for easier access/use.

class nicetoolbox.utils.git_utils.CustomRepo(repo_path)[source]

Customize the Repo class from gitpython for easier access/use.

This class extends the base class Repo from gitpython and provides additional methods for easier access and use of a git repository.

Parameters:

repo_path (str) – The path to the git repository.

Raises:

RuntimeError – If the repo_path is not a valid directory or a git repository.

None
get_git_hash()[source]

Get the latest commit hash and message of the git repository.

See also

Create a new Repo instance

Parameters:
  • path

    the path to either the root git directory or the bare git repo:

    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("C:\Users\mtrier\Development\git-python\.git")
    
    • In Cygwin, path may be a ‘cygdrive/…’ prefixed path.

    • If it evaluates to false, GIT_DIR is used, and if this also evals to false, 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:
  • InvalidGitRepositoryError

  • NoSuchPathError

Returns:

git.Repo

get_git_hash()[source]

Get the latest commit hash and message of the git repository.

Returns:

A tuple containing the latest commit hash (string) and the

commit message (string).

Return type:

tuple

Raises:

RuntimeError – If the repository is not a valid git repository.