MCPcopy Create free account
hub / github.com/libgit2/pygit2 / test_stash

Function test_stash

test/test_repository.py:397–431  ·  view source on GitHub ↗
(testrepo: Repository)

Source from the content-addressed store, hash-verified

395
396
397def test_stash(testrepo: Repository) -> None:
398 stash_hash = '6aab5192f88018cb98a7ede99c242f43add5a2fd'
399 stash_message = 'custom stash message'
400 sig = pygit2.Signature(
401 name='Stasher',
402 email='stasher@example.com',
403 time=1641000000, # fixed time so the oid is stable
404 offset=0,
405 )
406
407 # make sure we're starting with no stashes
408 assert [] == testrepo.listall_stashes()
409
410 # some changes to working dir
411 with (Path(testrepo.workdir) / 'hello.txt').open('w') as f:
412 f.write('new content')
413
414 testrepo.stash(sig, include_untracked=True, message=stash_message)
415 assert 'hello.txt' not in testrepo.status()
416
417 repo_stashes = testrepo.listall_stashes()
418 assert 1 == len(repo_stashes)
419 assert repr(repo_stashes[0]) == f'<pygit2.Stash{{{stash_hash}}}>'
420 assert repo_stashes[0].commit_id == stash_hash
421 assert repo_stashes[0].message == 'On master: ' + stash_message
422
423 testrepo.stash_apply()
424 assert 'hello.txt' in testrepo.status()
425 assert repo_stashes == testrepo.listall_stashes() # still the same stashes
426
427 testrepo.stash_drop()
428 assert [] == testrepo.listall_stashes()
429
430 with pytest.raises(KeyError):
431 testrepo.stash_pop()
432
433
434def test_stash_partial(testrepo: Repository) -> None:

Callers

nothing calls this directly

Calls 7

openMethod · 0.80
stashMethod · 0.80
statusMethod · 0.80
stash_applyMethod · 0.80
stash_dropMethod · 0.80
stash_popMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…