libvcs.sync.git
¶
For git(1)
.
Compare to:
fabtools.require.git
,
salt.states.git
,
ansible.builtin.git
Tool to manage a local git clone from an external git repository.
- exception libvcs.sync.git.GitStatusParsingException(git_status_output, *args)[source]¶
Bases:
LibVCSException
Raised when git status output is not in the expected format.
- exception libvcs.sync.git.GitRemoteOriginMissing(remotes, *args)[source]¶
Bases:
LibVCSException
Raised when git origin remote was not found.
- exception libvcs.sync.git.GitRemoteSetError(remote_name)[source]¶
Bases:
LibVCSException
Raised when a git remote could not be set.
- Parameters:
remote_name (str)
- Return type:
None
- exception libvcs.sync.git.GitNoBranchFound(*args)[source]¶
Bases:
LibVCSException
Raised with git branch could not be found.
- Parameters:
args (object)
- Return type:
None
- exception libvcs.sync.git.GitRemoteRefNotFound(git_tag, ref_output, *args)[source]¶
Bases:
CommandError
Raised when a git remote ref (tag, branch) could not be found.
- class libvcs.sync.git.GitRemote(name, fetch_url, push_url)[source]¶
Bases:
object
Structure containing git working copy information.
- class libvcs.sync.git.GitStatus(branch_oid=None, branch_head=None, branch_upstream=None, branch_ab=None, branch_ahead=None, branch_behind=None)[source]¶
Bases:
object
Git status information.
- Parameters:
- libvcs.sync.git.convert_pip_url(pip_url)[source]¶
Convert pip-style URL to a VCSLocation.
Prefixes stub URLs like ‘user@hostname:user/repo.git’ with ‘ssh://’. That’s required because although they use SSH they sometimes doesn’t work with a ssh:// scheme (e.g. Github). But we need a scheme for parsing. Hence we remove it again afterwards and return it as a stub. The manpage for git-clone(1) refers to this as the “scp-like styntax”.
- Return type:
- Parameters:
pip_url (str)
- class libvcs.sync.git.GitSync(*, url, path, remotes=None, **kwargs)[source]¶
Bases:
BaseSync
Tool to manage a local git clone from an external git repository.
Local git repository.
- Parameters:
Examples
import os from libvcs.sync.git import GitSync checkout = pathlib.Path(__name__) + '/' + 'my_libvcs' repo = GitSync( url="https://github.com/vcs-python/libvcs", path=checkout, remotes={ 'gitlab': 'https://gitlab.com/vcs-python/libvcs' } )
import os from libvcs.sync.git import GitSync checkout = pathlib.Path(__name__) + '/' + 'my_libvcs' repo = GitSync( url="https://github.com/vcs-python/libvcs", path=checkout, remotes={ 'gitlab': { 'fetch_url': 'https://gitlab.com/vcs-python/libvcs', 'push_url': 'https://gitlab.com/vcs-python/libvcs', }, } )
- bin_name: str = 'git'¶
VCS app name, e.g. ‘git’
- schemes: tuple[str, ...] = ('git+http', 'git+https', 'git+file')¶
List of supported schemes to register in
urlparse.uses_netloc
- __init__(*, url, path, remotes=None, **kwargs)[source]¶
Local git repository.
- Parameters:
- Return type:
None
Examples
import os from libvcs.sync.git import GitSync checkout = pathlib.Path(__name__) + '/' + 'my_libvcs' repo = GitSync( url="https://github.com/vcs-python/libvcs", path=checkout, remotes={ 'gitlab': 'https://gitlab.com/vcs-python/libvcs' } )
import os from libvcs.sync.git import GitSync checkout = pathlib.Path(__name__) + '/' + 'my_libvcs' repo = GitSync( url="https://github.com/vcs-python/libvcs", path=checkout, remotes={ 'gitlab': { 'fetch_url': 'https://gitlab.com/vcs-python/libvcs', 'push_url': 'https://gitlab.com/vcs-python/libvcs', }, } )
- get_revision()[source]¶
Return current revision. Initial repositories return ‘initial’.
- Return type:
- set_remotes(overwrite=False)[source]¶
Apply remotes in local repository to match GitSync’s configuration.
- set_remote(name, url, push=False, overwrite=False)[source]¶
Set remote with name and URL like git remote add.
- static chomp_protocol(url)[source]¶
Return clean VCS url from RFC-style url.
- Parameters:
url (str) – PIP-style url
- Return type:
URL as VCS software would accept it
- status()[source]¶
Retrieve status of project in dict format.
Wraps
git status --sb --porcelain=2
. Does not include changed files, yet.- Return type:
Status of current checked out repository
Examples
>>> git_repo = GitSync( ... url=f'file://{create_git_remote_repo()}', ... path=tmp_path ... ) >>> git_repo.obtain() >>> git_repo.status() GitStatus(branch_oid='...', branch_head='master', branch_upstream='origin/master', branch_ab='+0 -0', branch_ahead='0', branch_behind='0')