Skip to content

git

Git source control management implementation.

Classes

Git

Git(config: SCMConfig)

Git implementation.

Functions

add_path
add_path(path: str | Path) -> None

Add a path to the VCS.

assert_nondirty
assert_nondirty() -> None

Asserts that the repository is not dirty.

Raises:

DirtyWorkingDirectoryError

If the repository is not clean.

commit
commit(context: MutableMapping) -> None

Commit the changes.

commit_and_tag
commit_and_tag(
    files: list[Path | str],
    context: MutableMapping,
    dry_run: bool = False,
) -> None

Commit and tag files to the repository using the configuration.

get_all_tags
get_all_tags() -> list[str]

Return all tags in git.

is_available
is_available() -> bool

Is the VCS implementation usable?

latest_tag_info
latest_tag_info() -> LatestTagInfo

Return information about the latest tag.

Functions

assert_nondirty

assert_nondirty() -> None

Assert that the working directory is not dirty.

commit_info

commit_info(config: SCMConfig) -> dict

Get the commit info for the repo.

Parameters:

config

The source control configuration.

TYPE: SCMConfig

Returns:

dict

A dictionary containing information about the latest commit.

moveable_tag

moveable_tag(name: str) -> None

Create a new lightweight tag that should overwrite any previous tags with the same name.

Parameters:

name

The name of the moveable tag.

TYPE: str

push_remote

push_remote(
    remote_name: str, ref_name: str, force: bool = False
) -> None

Push the ref_name to the remote_name repository, optionally forcing the push.

revision_info

revision_info() -> dict

Returns a dictionary containing revision information.

If an error occurs while running the git command, the dictionary values will be set to None.

Returns:

dict

A dictionary with the following keys: - branch_name: The name of the current branch. - short_branch_name: A 20 lowercase characters of the branch name with special characters removed. - repository_root: The root directory of the Git repository.

tag

tag(
    name: str,
    sign: bool = False,
    message: Optional[str] = None,
) -> None

Create a tag of the new_version in git.

If only name is given, bumpversion uses a lightweight tag. Otherwise, it uses an annotated tag.

Parameters:

name

The name of the tag

TYPE: str

sign

True to sign the tag

TYPE: bool

DEFAULT: False

message

An optional message to annotate the tag.

TYPE: Optional[str]

DEFAULT: None

update_index

update_index() -> None

Update the git index.