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.
Examples¶
Stash work in progress, inspect it, restore it, then clear the stash list:
>>> from libvcs.cmd.git import Git
>>> git = Git(path=example_git_repo.path)
>>> _ = (example_git_repo.path / 'testfile.test').write_text('wip', encoding='utf-8')
>>> git.stashes.push(message='Work in progress')
'Saved working directory and index state ...'
>>> stashes = git.stashes.ls()
>>> len(stashes)
1
>>> stash = git.stashes.get(index=0)
>>> stash.show()
'...testfile.test...'
>>> stash.apply()
'...'
>>> git.stashes.clear()
''
API Reference¶
Wrap some of git-stash(1), manager.
Examples
>>> GitStashManager(path=tmp_path) <GitStashManager path=...>
>>> GitStashManager(path=tmp_path).run(trim=True) 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitStashManager( ... path=example_git_repo.path ... ).run(trim=True) 'No local changes to save'
Git stash push.
Save local modifications to a new stash entry.
Examples
>>> GitStashManager(path=example_git_repo.path).push(trim=True) 'No local changes to save'
>>> GitStashManager(path=example_git_repo.path).push(message='WIP', trim=True) 'No local changes to save'
Git stash clear.
Remove all stash entries.
Examples
>>> GitStashManager(path=example_git_repo.path).clear() ''
List stashes (raw output).
Examples
>>> GitStashManager(path=example_git_repo.path)._ls() []
List stashes.
Returns a
QueryListofGitStashEntryCmdobjects.Parses stash list format: -
stash@{0}: On master: message-stash@{0}: WIP on master: commitExamples
>>> GitStashManager(path=example_git_repo.path).ls() []
- Return type:
Get stash entry via filter lookup.
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
- Parameters:
- Return type:
Bases:
objectRun git commands targeting a specific stash entry.
Lite, typed, pythonic wrapper for git-stash(1) per-entry operations.
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... branch='master', ... message='WIP', ... ) <GitStashEntryCmd path=... index=0>
Return the stash reference string.
Git stash show for this stash entry.
- Parameters:
- Return type:
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).show(trim=True) 'error: stash@{0} is not a valid reference'
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(trim=True) 'error: stash@{0} is not a valid reference'
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(trim=True) 'error: stash@{0} is not a valid reference'
Git stash drop for this stash entry.
Remove this stash from the stash list.
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).drop(trim=True) 'error: stash@{0} is not a valid reference'
Git stash branch for this stash entry.
Create a new branch from this stash entry and apply the stash.
Examples
>>> GitStashEntryCmd( ... path=example_git_repo.path, ... index=0, ... ).create_branch('new-branch', trim=True) 'error: stash@{0} is not a valid reference'
Bases:
objectRun git stash commands (low-level, use
GitStashManager).Lite, typed, pythonic wrapper for git-stash(1).
Examples
>>> GitStashCmd(path=tmp_path) <GitStashCmd path=...>
>>> GitStashCmd(path=tmp_path).run(quiet=True, trim=True) 'fatal: not a git repository (or any of the parent directories): .git'
>>> GitStashCmd(path=example_git_repo.path).run(quiet=True) ''
Git stash list.
Examples
>>> GitStashCmd(path=example_git_repo.path).ls() ''
Push changes to the stash.
Wraps git stash push.
Examples
>>> GitStashCmd(path=example_git_repo.path).push(trim=True) 'No local changes to save'
>>> GitStashCmd(path=example_git_repo.path).push(path='.', trim=True) 'No local changes to save'
Git stash pop.
Examples
>>> GitStashCmd(path=example_git_repo.path).pop(trim=True) 'No stash entries found.'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=0, trim=True) 'error: stash@{0} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=1, index=True, trim=True) 'error: stash@{1} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).pop(stash=1, quiet=True, trim=True) 'error: stash@{1} is not a valid reference'
>>> GitStashCmd(path=example_git_repo.path).push(path='.', trim=True) 'No local changes to save'
Git stash save.
Examples
>>> GitStashCmd(path=example_git_repo.path).save(trim=True) 'No local changes to save'
>>> GitStashCmd(path=example_git_repo.path).save(message="Message", trim=True) 'No local changes to save'