ballet.util.git module

class ballet.util.git.CustomDiffer(endpoints)[source]

Bases: ballet.util.git.Differ

class ballet.util.git.Differ[source]

Bases: object

diff()[source]
Return type

DiffIndex

class ballet.util.git.LocalMergeBuildDiffer(repo)[source]

Bases: ballet.util.git.Differ

Diff files on a merge commit on the current active branch.

Merge parent order is guaranteed such that parent 1 is HEAD and parent 2 is topic [1].

repo

The repository to check the merge diff on. Must be currently on a branch where the most recent commit is a merge.

References

[1] https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging

class ballet.util.git.LocalPullRequestBuildDiffer(repo)[source]

Bases: ballet.util.git.PullRequestBuildDiffer

class ballet.util.git.NoOpDiffer(repo)[source]

Bases: ballet.util.git.PullRequestBuildDiffer

A differ that returns an empty changeset

diff()[source]
class ballet.util.git.PullRequestBuildDiffer(repo)[source]

Bases: ballet.util.git.Differ

Diff files from this pull request against a comparison ref

Parameters

repo (Repo) – repo

ballet.util.git.can_use_local_differ(repo)[source]

On some non-master branch

ballet.util.git.can_use_local_merge_differ(repo)[source]

Check the repo HEAD is on master after a merge commit

Checks for two qualities of the current project:

  1. The project repo’s head is the master branch

  2. The project repo’s head commit is a merge commit.

Note that fast-forward style merges will not cause the second condition to evaluate to true.

ballet.util.git.create_github_repo(github, owner, name)[source]

Create the repo :owner/:name

The authenticated account must have the permissions to create the desired repo.

  1. if the desired owner is the user, then this is straightforward

  2. if the desired owner is an organization, then the user must have permission to create a new repo for the organization

Return type

Repository

Returns

the created repository

Raises

github.GithubException.BadCredentialsException – if the token does not have permission to create the desired repo

ballet.util.git.did_git_push_succeed(push_info)[source]

Check whether a git push succeeded

A git push succeeded if it was not “rejected” or “remote rejected”, and if there was not a “remote failure” or an “error”.

Parameters

push_info (PushInfo) – push info

Return type

bool

ballet.util.git.get_branch(repo=None)[source]
Return type

str

ballet.util.git.get_diff_endpoints_from_commit_range(repo, commit_range)[source]

Get endpoints of a diff given a commit range

The resulting endpoints can be diffed directly:

a, b = get_diff_endpoints_from_commit_range(repo, commit_range)
a.diff(b)

For details on specifying git diffs, see git diff --help. For details on specifying revisions, see git help revisions.

Parameters
  • repo (Repo) – Repo object initialized with project root

  • commit_range (str) – commit range as would be interpreted by git diff command. Unfortunately only patterns of the form a..b and a...b are accepted. Note that the latter pattern finds the merge-base of a and b and uses it as the starting point for the diff.

Return type

Tuple[Diffable, Diffable]

Returns

starting commit, ending commit (inclusive)

Raises

ValueError – commit_range is empty or ill-formed

ballet.util.git.get_pull_request_outcomes(owner, repo)[source]
Return type

Iterator[str]

ballet.util.git.get_pull_requests(owner, repo, state='closed')[source]
Return type

dict

ballet.util.git.get_repo(repo=None)[source]
Return type

Repo

ballet.util.git.is_merge_commit(commit)[source]
Return type

bool

ballet.util.git.make_commit_range(a, b)[source]
Return type

str

ballet.util.git.push_branches_to_remote(repo, remote_name, branches)[source]

Push selected branches to origin

Similar to:

$ git push origin branch1:branch1 branch2:branch2
Raises

ballet.exc.BalletError – Push failed in some way

ballet.util.git.set_config_variables(repo, variables)[source]

Set config variables

Parameters
  • repo (Repo) – repo

  • variables (dict) – entries of the form 'user.email': 'you@example.com'

ballet.util.git.switch_to_new_branch(repo, name)[source]