git-sh-sync documentation¶
Python library to automatically synchronize git repositories via shell
Version: | 0.0 |
---|---|
Release: | 0.0.0 |
Welcome to the documentation!
git-sh-sync¶
GitHub: | https://github.com/spookey/git-sh-sync |
---|---|
Travis CI: | https://travis-ci.org/spookey/git-sh-sync |
Read the Docs: | https://git-sh-sync.readthedocs.io |
Contents¶
Proc Module¶
This module handles communication with the operating system. Namely launching commands.
-
git_sh_sync.proc.
CODE_SUCCESS
= 0¶ Returncode of a successful command
-
git_sh_sync.proc.
CHAR_NEWLINE
= '\n'¶ Newline character used for detailed log output
-
class
git_sh_sync.proc.
Command
(cmd, *, cwd=None, cin=None)¶ This is a class-based command runner using
subprocess
-
__init__
(cmd, *, cwd=None, cin=None)¶ Initialize a new command
Parameters: - cmd – Commandline of command to launch
- cwd – Launch cmd inside some other current working directory
- cin – Send data via stdin into cmd
-
cwd
¶ Returns: Current working directory or None
-
cin
¶ Returns: Stdin data or None
-
exc
¶ Returns: If launching the command raised some exception it is available here, otherwise None
-
code
¶ Returns: The shell returncode after launching. Will be None
on exception or before launch
-
launched
¶ Returns: True
if command was launched, otherwiseFalse
A command is considered launched if any of the
exception
or thereturncode
are not set toNone
-
success
¶ Returns: True
if command launch was successful, otherwiseFalse
A command is considered successful if no
exception
was thrown and thereturncode
equalsCODE_SUCCESS
-
fields
¶ Returns: Some information about the current command as dictionary Return type: dict Before the command was
launched
onlycmd
,cwd
andcin
are included. Afterlaunch
the result is extended bystdout
,stderr
,exc
andcode
.
-
__repr__
()¶ String representation of current command. Utilizes
fields()
andpprint.pformat()
for that.
-
repr
¶ Expand
__repr__()
with triple-quotes andCHAR_NEWLINE
.
-
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, 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
git
insideCommand
-
__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. Checksis_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
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 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: True
if successful elseFalse
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, elseFalse
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- branch_name – Name of the temporary branch (see
-
Disk Util¶
This modules handles disk operations. Namely combining paths, checking them and creating folders..
-
git_sh_sync.util.disk.
joined
(*locs)¶ Joins paths together.
Parameters: locs – Single path elements to join
together.Returns: A full path combined by the following rules: - Leading
slashes
are stripped from all but the first element Expanduser
is applied (~
)Expandvars
is applied (e.g.$HOME
is then the same as~
)- Finally
realpath
is applied to resolve symlinks and return a full path
- Leading
-
git_sh_sync.util.disk.
spare
(*locs, folder=False)¶ Checks if a path is not already occupied
Parameters: - locs – Input Parameter for
joined()
- folder – Flag to signal if to check for a file or folder
Returns: True
,False
orNone
by the following rules:- If a folder is present and folder =
True
:False
- If a folder is present and folder =
False
:None
- If a file is present and folder =
False
:False
- If a file is present and folder =
True
:None
- If nothing is present:
True
- locs – Input Parameter for