stash¶

For git-stash(1).

class libvcs.cmd.git.GitStashCmd(*, path, 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:
  • path (Union[str, PathLike[str]]) – Operates as PATH in the corresponding git subcommand.

  • cmd (Git | None)

Examples

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

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

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

  • cmd (Git | None)

Return type:

None

Examples

>>> GitStashCmd(path=tmp_path)
<GitStashCmd path=...>
>>> GitStashCmd(path=tmp_path).run(quiet=True)
'fatal: not a git repository (or any of the parent directories): .git'
>>> GitStashCmd(path=example_git_repo.path).run(quiet=True)
''
path: 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(path=example_git_repo.path).run()
'No local changes to save'
ls(*, 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(path=example_git_repo.path).ls()
''
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(path=example_git_repo.path).push()
'No local changes to save'
>>> GitStashCmd(path=example_git_repo.path).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(path=example_git_repo.path).pop()
'No stash entries found.'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=0)
'error: refs/stash@{0} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=1, index=True)
'error: refs/stash@{1} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=1, quiet=True)
'error: refs/stash@{1} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).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(path=example_git_repo.path).save()
'No local changes to save'
>>> GitStashCmd(path=example_git_repo.path).save(message="Message")
'No local changes to save'