Repo Module

This module allows working with git repositories.

git_sh_sync.repo.GIT_DIVIDER = '|-: ^_^ :-|'

Format divider (e.g. used in log) - Should be different from any text inside a commit message

class git_sh_sync.repo.GitStatus
Parameters:
  • clean – Is True if there are pending changes, otherwise False
  • conflicting – Files with conflicts \o/
  • deleted – Removed files
  • modified – Files with modifications
  • untracked – Files not yet added end up here
class git_sh_sync.repo.GitBranches
Parameters:
  • current – Currently active branch
  • all – All available branches (including current)
class git_sh_sync.repo.GitLog
Parameters:
  • short – Short commit hash
  • full – Complete commit hash
  • message – Commit message
class git_sh_sync.repo.Repository(location, *, master_branch='master', remote_name='origin', remote_url=None)

Handles communications with git repositories, using native git inside Command

__init__(location, *, master_branch='master', remote_name='origin', remote_url=None)

Initialize a new Repository

Parameters:
  • location – Local path of the repository
  • master_branch – Name of the master branch
  • remote_name – Default name of the remote
  • remote_url – Remote URL of the repository

Calls then initialize() to set everything up

is_repo

Verifies if current Repository is indeed a git repository.

initialize(remote_url=None)

Is called from inside __init__() to prepare the repository. Checks is_repo first to bail out early. If no remote_url is given a new repository is initialized. Otherwise a clone from the remote_url is attempted.

status

Determines current status of the repository.

Returns:Current status
Return type:GitStatus

Generates lists of changed files according to matching state.

branches()

Collects all branches of the repository

Returns:All branches
Return type:GitBranches

Signals current branch and a list of all other branches.

remote_names

Emit names of the remotes. Do not confuse this property with the remote_name, which acts as a default value for cloning or pushing actions.

Returns:Remote names
Return type:list
remote_url(remote=None)

Retrieve URL of remote by name.

Parameters:remote – Remote name
Returns:The URL as String or None if nothing was found
log(num=-1)

Retrieve log of repository

Parameters:num – Limit length of output. Use negative for unlimited output.
Returns:Log entries containing short-, full-hash and commit message.
Return type:list of GitLog
tags

Query existing tags.

Returns:Name of tags, newest first
Return type:list
tag(name)

Stick tags onto commits.

Parameters:name – Tag name
Returns:True if successful else False
checkout(treeish=None)

Checkout a commit, tag or branch.

Parameters:treeish – Commit (short or full), tag or branch. If left blank, master_branch is assumed
Returns:True if successful else False

If treeish is neither a known commit, tag or branch, a new branch is created.

mutate()

Collects all changes and tries to add/remove them.

Returns:True if everything went well, else False

Will freak out if there are conflicts detected - thus returning False and writing issues into the log.

scrub(branch_name=None)

Uses mutate() to handle all changes and commits them into a temporary branch. Will merge the branches back into the original branch afterwards.

Parameters:branch_name – Name of the temporary branch. Will use the current hostname if left blank.
Returns:True if everything went well (or there is nothing to do), False otherwise
cleanup(branch_name=None, remote_name=None)

Uses scrub() to form a new commit and pulls afterwards.

Parameters:
  • branch_name – Name of the temporary branch (see scrub())
  • remote_name – Name of the remote to pull from. For best results this should be some part of remote_names(). If left blank, class wide remote_name is taken.
Returns:

True on success, False otherwise

__call__(temp_branch_name=None, push_branch_name=None, remote_name=None)

Does a cleanup and tries to push afterwards. Will not push if something goes wrong with the cleanup.

Parameters:
  • temp_branch_name – Name of the temporary branch (see scrub())
  • push_branch_name – Name of the branch to push into. Will be set to class wide master_branch if set to None
  • remote_name – Name of the remote to pull from (see cleanup())
Returns:

True if everything went well, False otherwise