Base Git Provider

This is an incomplete provider. Currently, it acts as a base for GitHubRepo, and does not support cloning arbitrary Git URLs.

class modify_repos.repo.git.GitRepo(script, remote_id)

Bases: Repo

Subclass this to define how to manipulate Git repositories.

Parameters:
  • script (Script[t.Any]) – The script being run to modify this repo.

  • remote_id (str)

add_untracked: bool = False

Whether to consider untracked files when checking if there are changes and adding files in the auto commit(). By default this is false to avoid accidentally adding generated files, but this means you need to remember to call git_add() for any completely new files.

git_cmd(*args)

Call and pass args to the git command.

Parameters:

args (str | Path) – Command line arguments to the git command.

Return type:

CompletedProcess[str]

reset_target()

Reset the base branch that will be branched off of and merged into. This should ensure the repository is clean and up to date, discarding any changes from previous unsuccessful runs. Called by run().

Return type:

None

reset_branch()

Create or reset the work branch. This should ensure the branch is freshly created from the target branch. Called by run().

Return type:

None

needs_commit()

Check if there are uncommitted changes. Called by auto_commit_if_needed().

Return type:

bool

auto_commit()

Create a commit unconditionally. This is called by auto_commit_if_needed() to create the automatic commit when there are uncommitted changes, and should add those changes to the commit. It should not be called to create other intermediate commits. It should use Script.message as the commit message.

Return type:

None

needs_submit()

Check if there are commits that have not been pushed upstream. Called by submit_if_needed().

Return type:

bool

submit()

Submit the changes upstream. What this means depends on the implementation; whether it merges, creates a PR, or something else.

Return type:

None

commit(message, add=False)

Create a commit with the given message.

Parameters:
  • message (str) – The commit message.

  • add (bool) – Update tracked files while committing. Disabled by default. Alternatively, call {meth}`add_files` first.

Return type:

None

add_files(*items, update=False, all=False)

Call git add.

Parameters:
  • items (str | Path) – Files to add or update. Can be empty.

  • update (bool) – Update all tracked files.

  • all (bool) – Add all files, including untracked, excluding ignored.

Return type:

None

rm_files(*items)

Call git rm for any given files that exist. Missing files are skipped so that the command doesn’t return an error.

Parameters:

items (str | Path) – Files to delete if they exist.

Return type:

None