gitmopy.git

gitmopy’s Git-related utility functions.

Module Contents

class gitmopy.git.CatchRemoteException(remote)[source]

Context manager to catch GitCommandError when pushing to a remote.

Also stores whether the issue is that the remote has no upstream branch.

Parameters:

remote (str) – Name of the remote repository that is being pushed to.

error = False[source]
remote[source]
set_upsteam = False[source]
gitmopy.git.commits_ahead(repo)[source]

Get the number of commits the local current branch is behind for each remote.

Parameters:

repo (Repo) – GitPython repository object.

Returns:

Number of commits the local current branch is behind for each remote.

Return type:

int

gitmopy.git.commits_behind(repo)[source]

Get the number of commits the local current branch is behind for each remote.

Parameters:

repo (Repo) – GitPython repository object.

Returns:

Number of commits the local current branch is behind for each remote.

Return type:

int

gitmopy.git.fetch_all(repo)[source]

Fetch all remotes of a GitPython repository.

Parameters:

repo (git.Repo) – Repository to fetch remotes from.

gitmopy.git.format_remotes_diff(repo)[source]

Format the remotes diff.

Parameters:

repo (Repo) – GitPython repository object.

Returns:

Formatted remotes diff.

Return type:

str

gitmopy.git.get_files_status(repo)[source]

Make a dictionnary of the files’ status in a GitPython repository.

Keys are “staged”, “unstaged” and “untracked”. Values are lists of file paths.

Parameters:

repo (git.Repo) – Repository to get files’ status from.

Returns:

Dictionnary of files’ status.

Return type:

Dict[str, List[str]]

gitmopy.git.get_staged(repo)[source]

Get staged files from a GitPython repository.

Parameters:

repo (git.Repo) – Repository to get staged files from.

Returns:

File paths of staged files.

Return type:

List[str]

gitmopy.git.get_unstaged(repo)[source]

Get unstaged files from a GitPython repository.

Parameters:

repo (git.Repo) – Repository to get unstaged files from.

Returns:

File paths of unstaged files.

Return type:

List[str]

gitmopy.git.get_untracked(repo)[source]

Get untracked files from a GitPython repository.

Parameters:

repo (git.Repo) – Repository to get untracked files from.

Returns:

File paths of untracked files.

Return type:

List[str]

gitmopy.git.has_upstreams(repo, remotes, branch_name)[source]

Check which remotes have a branch with a given name.

Parameters:
  • repo (git.Repo) – Repository to check branches from.

  • remotes (List[Union[str, Remote]]) – List of remotes to check.

  • branch_name (str) – Name of the branch to check.

Returns:

Dictionnary of booleans indicating if each remote has the

branch.

Return type:

Dict[str, bool]

gitmopy.git.unstage(repo, files)[source]

Unstage files from the index.

Parameters:
  • repo (Repo) – GitPython repository object.

  • files (List[str]) – List of files to unstage.

Return type:

None