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
Trueif there are pending changes, otherwiseFalse - conflicting – Files with conflicts
\o/ - deleted – Removed files
- modified – Files with modifications
- untracked – Files not yet added end up here
- clean – Is
-
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
gitinsideCommand-
__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
Repositoryis indeed a git repository.
-
initialize(remote_url=None)¶ Is called from inside
__init__()to prepare the repository. Checksis_repofirst 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: GitStatusGenerates lists of changed files according to matching state.
-
branches()¶ Collects all branches of the repository
Returns: All branches Return type: GitBranchesSignals 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 Noneif 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
Query existing tags.
Returns: Name of tags, newest first Return type: list
-
tag(name)¶ Stick tags onto commits.
Parameters: name – Tag name Returns: Trueif successful elseFalse
-
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: Trueif successful elseFalseIf 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: Trueif everything went well, elseFalseWill freak out if there are conflicts detected - thus returning
Falseand 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 hostnameif left blank.Returns: Trueif everything went well (or there is nothing to do),Falseotherwise
-
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: Trueon success,Falseotherwise- branch_name – Name of the temporary branch (see
-