remote¶

For git-remote(1).

class libvcs.cmd.git.GitRemoteCmd(*, path, cmd=None)[source]¶

Bases: object

Run commands directly for a git remote on a git repository.

Lite, typed, pythonic wrapper for git-remote(1).

Parameters:
  • path (Union[str, PathLike[str]]) – Operates as PATH in the corresponding git subcommand.

  • cmd (Git | None)

Examples

>>> GitRemoteCmd(path=tmp_path)
<GitRemoteCmd path=...>
>>> GitRemoteCmd(path=tmp_path).run(verbose=True)
'fatal: not a git repository (or any of the parent directories): .git'
>>> GitRemoteCmd(path=example_git_repo.path).run(verbose=True)
'origin\tfile:///...'
__init__(*, path, cmd=None)[source]¶

Lite, typed, pythonic wrapper for git-remote(1).

Parameters:
  • path (Union[str, PathLike[str]]) – Operates as PATH in the corresponding git subcommand.

  • cmd (Git | None)

Return type:

None

Examples

>>> GitRemoteCmd(path=tmp_path)
<GitRemoteCmd path=...>
>>> GitRemoteCmd(path=tmp_path).run(verbose=True)
'fatal: not a git repository (or any of the parent directories): .git'
>>> GitRemoteCmd(path=example_git_repo.path).run(verbose=True)
'origin\tfile:///...'
path: Path¶

Directory to check out

run(command=None, local_flags=None, *, verbose=None, log_in_real_time=False, check_returncode=None, **kwargs)[source]¶

Run command against a git remote.

Wraps git remote.

Return type:

str

Parameters:
  • command (Literal['add', 'rename', 'remove', 'set-branches', 'set-head', 'set-branch', 'get-url', 'set-url', 'set-url --add', 'set-url --delete', 'prune', 'show', 'update'] | None)

  • local_flags (list[str] | None)

  • verbose (bool | None)

  • log_in_real_time (bool)

  • check_returncode (bool | None)

  • kwargs (Any)

Examples

>>> GitRemoteCmd(path=example_git_repo.path).run()
'origin'
>>> GitRemoteCmd(path=example_git_repo.path).run(verbose=True)
'origin\tfile:///...'
add(*, name, url, fetch=None, track=None, master=None, mirror=None, log_in_real_time=False, check_returncode=None)[source]¶

Git remote add.

Return type:

str

Parameters:
  • name (str)

  • url (str)

  • fetch (bool | None)

  • track (str | None)

  • master (str | None)

  • mirror (Literal['push', 'fetch'] | bool | None)

  • log_in_real_time (bool)

  • check_returncode (bool | None)

Examples

>>> git_remote_repo = create_git_remote_repo()
>>> GitRemoteCmd(path=example_git_repo.path).add(
...     name='my_remote', url=f'file://{git_remote_repo}'
... )
''
rename(*, old, new, progress=None, log_in_real_time=False, check_returncode=None)[source]¶

Git remote rename.

Return type:

str

Parameters:
  • old (str)

  • new (str)

  • progress (bool | None)

  • log_in_real_time (bool)

  • check_returncode (bool | None)

Examples

>>> git_remote_repo = create_git_remote_repo()
>>> GitRemoteCmd(
...     path=example_git_repo.path
... ).rename(old='origin', new='new_name')
''
>>> GitRemoteCmd(path=example_git_repo.path).run()
'new_name'
remove(*, name, log_in_real_time=False, check_returncode=None)[source]¶

Git remote remove.

Return type:

str

Parameters:
  • name (str)

  • log_in_real_time (bool)

  • check_returncode (bool | None)

Examples

>>> GitRemoteCmd(path=example_git_repo.path).remove(name='origin')
''
>>> GitRemoteCmd(path=example_git_repo.path).run()
''
show(*, name=None, verbose=None, no_query_remotes=None, log_in_real_time=False, check_returncode=None)[source]¶

Git remote show.

Return type:

str

Parameters:
  • name (str | None)

  • verbose (bool | None)

  • no_query_remotes (bool | None)

  • log_in_real_time (bool)

  • check_returncode (bool | None)

Examples

>>> GitRemoteCmd(path=example_git_repo.path).show()
'origin'
prune(*, name, dry_run=None, log_in_real_time=False, check_returncode=None)[source]¶

Git remote prune.

Return type:

str

Parameters:
  • name (str)

  • dry_run (bool | None)

  • log_in_real_time (bool)

  • check_returncode (bool | None)

Examples

>>> git_remote_repo = create_git_remote_repo()
>>> GitRemoteCmd(path=example_git_repo.path).prune(name='origin')
''
>>> GitRemoteCmd(path=example_git_repo.path).prune(name='origin', dry_run=True)
''
get_url(*, name, push=None, _all=None, log_in_real_time=False, check_returncode=None)[source]¶

Git remote get-url.

Return type:

str

Parameters:
  • name (str)

  • push (bool | None)

  • _all (bool | None)

  • log_in_real_time (bool)

  • check_returncode (bool | None)

Examples

>>> git_remote_repo = create_git_remote_repo()
>>> GitRemoteCmd(path=example_git_repo.path).get_url(name='origin')
'file:///...'
>>> GitRemoteCmd(path=example_git_repo.path).get_url(name='origin', push=True)
'file:///...'
>>> GitRemoteCmd(path=example_git_repo.path).get_url(name='origin', _all=True)
'file:///...'
set_url(*, name, url, old_url=None, push=None, add=None, delete=None, log_in_real_time=False, check_returncode=None)[source]¶

Git remote set-url.

Return type:

str

Parameters:
  • name (str)

  • url (str)

  • old_url (str | None)

  • push (bool | None)

  • add (bool | None)

  • delete (bool | None)

  • log_in_real_time (bool)

  • check_returncode (bool | None)

Examples

>>> git_remote_repo = create_git_remote_repo()
>>> GitRemoteCmd(path=example_git_repo.path).set_url(
...     name='origin',
...     url='http://localhost'
... )
''
>>> GitRemoteCmd(path=example_git_repo.path).set_url(
...     name='origin',
...     url='http://localhost',
...     push=True
... )
''
>>> GitRemoteCmd(path=example_git_repo.path).set_url(
...     name='origin',
...     url='http://localhost',
...     add=True
... )
''
>>> current_url = GitRemoteCmd(
...     path=example_git_repo.path,
... ).get_url(name='origin')
>>> GitRemoteCmd(path=example_git_repo.path).set_url(
...     name='origin',
...     url=current_url,
...     delete=True
... )
'fatal: Will not delete all non-push URLs'