gittools.py

Wrap some git commands for use in programmatic revision control.

Originally developed for samplemap.py, so it has limited functionality dictated by that program’s limited use cases.

Generalized because I know I would like to use it eventually in syqada.

gittools.clean_environment(terms=['GIT_OBJECT_DIRECTORY', 'GIT_DIR'])[source]

Make sure that the user running this doesn’t have these two environment variables set (a different list may be expunged by providing a list of terms upon invocation).

gittools.git_commit(message, gitdir, all=False)[source]

Commit all added files, using message as the commit message.

Return True upon success, False upon failure.

gitdir is the path to the repository

gittools.git_fileadd(file, gitdir)[source]

git add a file for later commit.

Return True upon success, False upon failure.

gitdir is the path to the repository

gittools.git_filecommit(file, message, gitdir, already_controlled=True)[source]

Add and commit a single file, using message as the commit message.

Return True upon success, False upon failure.

if already_controlled is true, fail if the file is not already under version control in the repository. Default True on the assumption that this library is mostly about tight control of a few well-known objects.

gitdir is the path to the repository

gittools.git_filestatus(file, gitdir)[source]

Test the status of a file.

Return one of CLEAN, UNTRACKED, MODIFIED, ADDED, INVALID

Statuses of INVALID print error messages to sys.stderr

if file is None, return the whole result of git status

gitdir is the path to the repository

gittools.git_init(gitdir)[source]

Create and initialize a repository at path location gitdir

Return True upon success, False upon failure.

Fail complaining if gitdir exists.

gittools.git_lastlog(gitdir)[source]

Return last log message.

gitdir is the path to the repository

gittools.git_reset(gitdir)[source]

Reset hard to clean up.

Return True upon success, False upon failure.

gitdir is the path to the repository

gittools.git_version_ok(version=None)[source]

Make sure the version of git supports our needs. Default 2.3.8.

version is only for testing, or possibly for fixing failures caused by this method refusing to accept values that actually work with this module.