stash#

For git-stash(1).

class libvcs.cmd.git.GitStashCmd(*, dir, cmd=None)[source]#

Bases: object

Run commands directly against a git stash storage for a git repo.

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

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

  • cmd (Git | None) –

Examples

>>> GitStashCmd(dir=tmp_path)
<GitStashCmd dir=...>
>>> GitStashCmd(dir=tmp_path).run(quiet=True)
'fatal: not a git repository (or any of the parent directories): .git'
>>> GitStashCmd(dir=git_local_clone.dir).run(quiet=True)
''
__init__(*, dir, cmd=None)[source]#

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

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

  • cmd (Git | None) –

Return type:

None

Examples

>>> GitStashCmd(dir=tmp_path)
<GitStashCmd dir=...>
>>> GitStashCmd(dir=tmp_path).run(quiet=True)
'fatal: not a git repository (or any of the parent directories): .git'
>>> GitStashCmd(dir=git_local_clone.dir).run(quiet=True)
''
dir: Path#

Directory to check out

run(command=None, local_flags=None, *, quiet=None, cached=None, log_in_real_time=False, check_returncode=None, **kwargs)[source]#

Run a command against a git repository’s stash storage.

Wraps git stash.

Return type:

str

Parameters:
  • command (Literal['list', 'show', 'save', 'drop', 'branch', 'pop', 'apply', 'push', 'clear', 'create', 'store'] | None) –

  • local_flags (list[str] | None) –

  • quiet (bool | None) –

  • cached (bool | None) –

  • log_in_real_time (bool) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Examples

>>> GitStashCmd(dir=git_local_clone.dir).run()
'No local changes to save'
_list(*, log_in_real_time=False, check_returncode=None)[source]#

Git stash list.

Return type:

str

Parameters:
  • log_in_real_time (bool) –

  • check_returncode (bool | None) –

Examples

>>> GitStashCmd(dir=git_local_clone.dir)._list()
''
push(*, path=None, patch=None, staged=None, log_in_real_time=False, check_returncode=None, **kwargs)[source]#

Git stash update.

TODO: Fill-in

Return type:

str

Parameters:

Examples

>>> GitStashCmd(dir=git_local_clone.dir).push()
'No local changes to save'
>>> GitStashCmd(dir=git_local_clone.dir).push(path='.')
'No local changes to save'
pop(*, stash=None, index=None, quiet=None, log_in_real_time=False, check_returncode=None, **kwargs)[source]#

Git stash pop.

Return type:

str

Parameters:
  • stash (int | None) –

  • index (bool | None) –

  • quiet (bool | None) –

  • log_in_real_time (bool) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Examples

>>> GitStashCmd(dir=git_local_clone.dir).pop()
'No stash entries found.'
>>> GitStashCmd(dir=git_local_clone.dir).pop(stash=0)
'error: refs/stash@{0} is not a valid reference'
>>> GitStashCmd(dir=git_local_clone.dir).pop(stash=1, index=True)
'error: refs/stash@{1} is not a valid reference'
>>> GitStashCmd(dir=git_local_clone.dir).pop(stash=1, quiet=True)
'error: refs/stash@{1} is not a valid reference'
>>> GitStashCmd(dir=git_local_clone.dir).push(path='.')
'No local changes to save'
save(*, message=None, staged=None, keep_index=None, patch=None, include_untracked=None, all=None, quiet=None, log_in_real_time=False, check_returncode=None, **kwargs)[source]#

Git stash save.

Return type:

str

Parameters:
  • message (str | None) –

  • staged (int | None) –

  • keep_index (int | None) –

  • patch (bool | None) –

  • include_untracked (bool | None) –

  • all (bool | None) –

  • quiet (bool | None) –

  • log_in_real_time (bool) –

  • check_returncode (bool | None) –

  • kwargs (Any) –

Examples

>>> GitStashCmd(dir=git_local_clone.dir).save()
'No local changes to save'
>>> GitStashCmd(dir=git_local_clone.dir).save(message="Message")
'No local changes to save'