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

Function test_stash_aborted_from_callbacks

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

Source from the content-addressed store, hash-verified

505
506
507def test_stash_aborted_from_callbacks(testrepo: Repository) -> None:
508 sig = pygit2.Signature(
509 name='Stasher', email='stasher@example.com', time=1641000000, offset=0
510 )
511
512 # some changes to working dir
513 with (Path(testrepo.workdir) / 'hello.txt').open('w') as f:
514 f.write('new content')
515 with (Path(testrepo.workdir) / 'untracked.txt').open('w') as f:
516 f.write('yo')
517
518 # create the stash
519 testrepo.stash(sig, include_untracked=True, message='custom stash message')
520
521 # define callbacks that will abort the unstash process
522 # just as libgit2 is ready to write the files to disk
523 class MyStashApplyCallbacks(pygit2.StashApplyCallbacks):
524 def stash_apply_progress(self, progress: StashApplyProgress) -> None:
525 if progress == StashApplyProgress.CHECKOUT_UNTRACKED:
526 raise InterruptedError('Stop applying the stash!')
527
528 # attempt to apply and delete the stash; the callbacks will interrupt that
529 with pytest.raises(InterruptedError):
530 testrepo.stash_pop(callbacks=MyStashApplyCallbacks())
531
532 # we interrupted right before the checkout part of the unstashing process,
533 # so the untracked file shouldn't be here
534 assert not (Path(testrepo.workdir) / 'untracked.txt').exists()
535
536 # and hello.txt should be as it is on master
537 with (Path(testrepo.workdir) / 'hello.txt').open('r') as f:
538 assert f.read() == 'hello world\nhola mundo\nbonjour le monde\n'
539
540 # and since we didn't let stash_pop run to completion, the stash itself should still be here
541 repo_stashes = testrepo.listall_stashes()
542 assert 1 == len(repo_stashes)
543 assert repo_stashes[0].message == 'On master: custom stash message'
544
545
546def test_stash_apply_checkout_options(testrepo: Repository) -> None:

Callers

nothing calls this directly

Calls 7

openMethod · 0.80
stashMethod · 0.80
stash_popMethod · 0.80
existsMethod · 0.80
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…