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

Function test_stash_partial

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

Source from the content-addressed store, hash-verified

432
433
434def test_stash_partial(testrepo: Repository) -> None:
435 stash_message = 'custom stash message'
436 sig = pygit2.Signature(
437 name='Stasher', email='stasher@example.com', time=1641000000, offset=0
438 )
439
440 # make sure we're starting with no stashes
441 assert [] == testrepo.listall_stashes()
442
443 # some changes to working dir
444 with (Path(testrepo.workdir) / 'hello.txt').open('w') as f:
445 f.write('stash me')
446 with (Path(testrepo.workdir) / 'untracked2.txt').open('w') as f:
447 f.write('do not stash me')
448
449 assert testrepo.status()['hello.txt'] == FileStatus.WT_MODIFIED
450 assert testrepo.status()['bye.txt'] == FileStatus.WT_NEW
451 assert testrepo.status()['untracked2.txt'] == FileStatus.WT_NEW
452
453 def stash_pathspecs(paths: list[str]) -> bool:
454 stash_id = testrepo.stash(
455 sig, message=stash_message, keep_all=True, paths=paths
456 )
457 stash_commit = testrepo[stash_id].peel(pygit2.Commit)
458 stash_diff = testrepo.diff(stash_commit.parents[0], stash_commit)
459 stash_files = set(
460 patch.delta.new_file.path for patch in utils.diff_safeiter(stash_diff)
461 )
462 return stash_files == set(paths)
463
464 # Stash a modified file
465 assert stash_pathspecs(['hello.txt'])
466
467 # Stash one of several untracked files
468 assert stash_pathspecs(['bye.txt'])
469
470 # Stash a modified file and an untracked file
471 assert stash_pathspecs(['hello.txt', 'bye.txt'])
472
473
474def test_stash_progress_callback(testrepo: Repository) -> None:

Callers

nothing calls this directly

Calls 4

stash_pathspecsFunction · 0.85
openMethod · 0.80
statusMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…