stash¶
For git-stash(1).
Overview¶
Manage git stashes using GitStashManager (collection-level)
and GitStashEntryCmd (per-stash operations).
Note
GitStashCmd is the legacy interface. Use git.stashes
(GitStashManager) for the new Manager/Cmd pattern.
Example¶
from libvcs.cmd.git import Git
git = Git(path='/path/to/repo')
# Push changes to stash
git.stashes.push(message='Work in progress')
# List all stashes
stashes = git.stashes.ls()
# Get a specific stash and operate on it
stash = git.stashes.get(index=0)
stash.show()
stash.apply()
stash.drop()
# Clear all stashes
git.stashes.clear()
API Reference¶
- class libvcs.cmd.git.GitStashManager[source]¶
Bases:
objectTraverse and manage git stashes with ORM-like filtering via QueryList.
Wrap some of git-stash(1), manager.
Examples
>>> GitStashManager(path=tmp_path) <GitStashManager path=...>
>>> GitStashManager(path=tmp_path).run() 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitStashManager( ... path=example_git_repo.path ... ).run() 'No local changes to save'
- __init__(*, path, cmd=None)[source]¶
Wrap some of git-stash(1), manager.
- Parameters:
- Return type:
None
Examples
>>> GitStashManager(path=tmp_path) <GitStashManager path=...>
>>> GitStashManager(path=tmp_path).run() 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitStashManager( ... path=example_git_repo.path ... ).run() 'No local changes to save'
- run(command=None, local_flags=None, *, quiet=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:
- Parameters:
Examples
>>> GitStashManager(path=example_git_repo.path).run() 'No local changes to save'
- push(*, message=None, path=None, patch=None, staged=None, keep_index=None, include_untracked=None, _all=None, quiet=None, log_in_real_time=False, check_returncode=None)[source]¶
Git stash push.
Save local modifications to a new stash entry.
- Parameters:
- Return type:
Examples
>>> GitStashManager(path=example_git_repo.path).push() 'No local changes to save'
>>> GitStashManager(path=example_git_repo.path).push(message='WIP') 'No local changes to save'
- clear(*, log_in_real_time=False, check_returncode=None)[source]¶
Git stash clear.
Remove all stash entries.
Examples
>>> GitStashManager(path=example_git_repo.path).clear() ''
- _ls()[source]¶
List stashes (raw output).
Examples
>>> GitStashManager(path=example_git_repo.path)._ls() []
- ls()[source]¶
List stashes.
Returns a QueryList of GitStashEntryCmd objects.
Parses stash list format: -
stash@{0}: On master: message-stash@{0}: WIP on master: commit- Return type:
Examples
>>> GitStashManager(path=example_git_repo.path).ls() []
- get(*args, **kwargs)[source]¶
Get stash entry via filter lookup.
- Return type:
- Parameters:
Examples
>>> GitStashManager( ... path=example_git_repo.path ... ).get(index=0) Traceback (most recent call last): exec(compile(example.source, filename, "single", ... return self.ls().get(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "..._internal/query_list.py", line ..., in get raise ObjectDoesNotExist libvcs._internal.query_list.ObjectDoesNotExist
- class libvcs.cmd.git.GitStashEntryCmd[source]¶
Bases:
objectRun git commands targeting a specific stash entry.
Lite, typed, pythonic wrapper for git-stash(1) per-entry operations.
- Parameters:
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... branch='master', ... message='WIP', ... ) <GitStashEntryCmd path=... index=0>
- __init__(*, path, index, branch=None, message='', cmd=None)[source]¶
Lite, typed, pythonic wrapper for git-stash(1) per-entry operations.
- Parameters:
- Return type:
None
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... branch='master', ... message='WIP', ... ) <GitStashEntryCmd path=... index=0>
- run(command=None, local_flags=None, *, log_in_real_time=False, check_returncode=None, **kwargs)[source]¶
Run command against a git stash entry.
Wraps git stash.
- show(*, stat=None, patch=None, include_untracked=None, log_in_real_time=False, check_returncode=None)[source]¶
Git stash show for this stash entry.
- Parameters:
- Return type:
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).show() 'error: stash@{0} is not a valid reference'
- apply(*, index=None, quiet=None, log_in_real_time=False, check_returncode=None)[source]¶
Git stash apply for this stash entry.
Apply the stash without removing it from the stash list.
- Parameters:
- Return type:
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).apply() 'error: stash@{0} is not a valid reference'
- pop(*, index=None, quiet=None, log_in_real_time=False, check_returncode=None)[source]¶
Git stash pop for this stash entry.
Apply the stash and remove it from the stash list.
- Parameters:
- Return type:
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).pop() 'error: stash@{0} is not a valid reference'
- drop(*, quiet=None, log_in_real_time=False, check_returncode=None)[source]¶
Git stash drop for this stash entry.
Remove this stash from the stash list.
- Parameters:
- Return type:
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).drop() 'error: stash@{0} is not a valid reference'
- create_branch(branch_name, *, log_in_real_time=False, check_returncode=None)[source]¶
Git stash branch for this stash entry.
Create a new branch from this stash entry and apply the stash.
- Parameters:
- Return type:
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).create_branch('new-branch') 'error: stash@{0} is not a valid reference'
- class libvcs.cmd.git.GitStashCmd[source]¶
Bases:
objectRun git stash commands (low-level, use GitStashManager for traversal).
Lite, typed, pythonic wrapper for git-stash(1).
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:
- 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) ''
- run(command=None, local_flags=None, *, quiet=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:
- Parameters:
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.
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]¶
Push changes to the stash.
Wraps git stash push.
- Parameters:
- Return type:
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:
- Parameters:
Examples
>>> GitStashCmd(path=example_git_repo.path).pop() 'No stash entries found.'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=0) 'error: stash@{0} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=1, index=True) 'error: stash@{1} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=1, quiet=True) 'error: 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:
- Parameters:
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'