Git Wrapper
Zoo tools wrapper around gitpython with a strong focus zoo package release workflows.
- exception DirtyGitRepoException
Bases:
ExceptionRaised when the current branch has uncommitted changes.
- exception IncorrectCurrentBranchException
Bases:
ExceptionRaised when the current branch isn’t the primary master branch.
- exception GitCommandError
Bases:
ExceptionRaised when the current branch isn’t the primary master branch.
- exception InvalidGitRepositoryError
Bases:
ExceptionRaised when the current branch isn’t the primary master branch.
- class GitRepo(repoPath=None)
Bases:
objectWrapper around the gitpython Repo class to provide Zoo related operations.
- Parameters:
repoPath (str) – The physical disk or URL to the Git repository
- classmethod clone(repoPath, destination, **kwargs)
Clones the given git URL to the destination path.
- checkout(name)
Checks out a branch or tag based on the name.
- Parameters:
name (str) – The branch or tag name to checkout ie. master
- Returns:
The branch instance which was checked out. see git.Head class.
- Return type:
git.Head
- assertRepo()
Checks whether this repo is either dirty ie. uncommitted changes in which case a
DirtyGitRepoExceptionwill be raised. or the current branch isn’t master in which caseIncorrectCurrentBranchExceptionis raised.- Returns:
True when everything checks out to be fine.
- Return type:
- Raises:
DirtyGitRepoException – In the case we’re the current branch has uncommitted changes
IncorrectCurrentBranchException – In the case that the current branch isn’t master which is required when releasing our packages.
AssertionError – if the repository is bare
- archive(fileName)
Archive the current repo state as a zip into a temp location.
Note
Relies heavily on gitpython to do the packing.
- tags()
Returns a sorted list based on the commit date of all tags on the repository
- Return type:
iterable[
git.TagReference]
- latestTag()
Returns the latest tag based on the commit date.
- Return type:
git.TagReference
- commit(msg)
Commits All current changes to the branch with the given message.
- Parameters:
msg (str) – The commit message
- createTag(name, message)
Creates and returns a new tag locally. use
GitRepo.pushTag()to push to origin.
- pushChanges()
Pushes any uncommitted changes to origin.
- pullTags()
Does a fetch –tags on the current branch
- pushTag(tag)
Pushes a single tag to origin.
- Parameters:
tag (
git.TagReference) – The tag to push.
- hasChangesSinceLastTag()
Checks to see if there’s been any commits since the latest tag.
- Return type:
- commitMessagesSinceTag(firstTag, secondTag=None)
finds and returns all commits between to tags if secondTag is None then the HEAD will be used.
- Parameters:
firstTag (
gitTagReferenceor str) – The first/ older tag to to search from.secondTag (
gitTagReferenceor str or None) – The Tag to search to if None then HEAD will be used.
- Returns:
A generator where each element is commit object containing the date,author and message.
- Return type:
iterable[
Commit]
Note
Ignores certain commit messages like “Merge branch”, “auto stash”, “Create new version Tag”(which is done by our release tool). Exits early if theres a fatal reply by git.log
- class Commit
Bases:
dictWrapper dict for a single git commit which contains the date, author and message.
- property date
- property author
- property message
- tagToChangeLog(repo, previousTag, toTag, version=None, change=None)
Given the previous tag and the future tag(toTag) a changelog object is generated based on the vcs commit log, removing any commits which need to be ignored.
- Parameters:
repo (
GitRepo) – The GitRepo to operate on.previousTag (
git.TagReference) – The tag to start filtering from ie. 1.2.0 while toTag would be 1.2.1toTag (
git.TagReference) – The latest tag to filter commits too.change (
changelog.Changelogor None) – The changelog instance to update or None which will create a new instance.version (str) – The Version to use for the commit messages. only used
- Returns:
Either the same instance provided by change or a newly created instance.
- Return type:
changelog.Changelog