MCPcopy Create free account
hub / github.com/libgit2/git2go / TestApplyToTree

Function TestApplyToTree

diff_test.go:466–595  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

464}
465
466func TestApplyToTree(t *testing.T) {
467 repo := createTestRepo(t)
468 defer cleanupTestRepo(t, repo)
469
470 seedTestRepo(t, repo)
471
472 commitA, treeA := addAndGetTree(t, repo, "file", "a")
473 defer commitA.Free()
474 defer treeA.Free()
475 commitB, treeB := addAndGetTree(t, repo, "file", "b")
476 defer commitB.Free()
477 defer treeB.Free()
478 commitC, treeC := addAndGetTree(t, repo, "file", "c")
479 defer commitC.Free()
480 defer treeC.Free()
481
482 diffAB, err := repo.DiffTreeToTree(treeA, treeB, nil)
483 checkFatal(t, err)
484
485 diffAC, err := repo.DiffTreeToTree(treeA, treeC, nil)
486 checkFatal(t, err)
487
488 errMessageDropped := errors.New("message dropped")
489
490 for _, tc := range []struct {
491 name string
492 tree *Tree
493 diff *Diff
494 applyHunkCallback ApplyHunkCallback
495 applyDeltaCallback ApplyDeltaCallback
496 err error
497 expectedDiff *Diff
498 }{
499 {
500 name: "applying patch produces the same diff",
501 tree: treeA,
502 diff: diffAB,
503 expectedDiff: diffAB,
504 },
505 {
506 name: "applying a conflicting patch errors",
507 tree: treeB,
508 diff: diffAC,
509 err: &GitError{
510 Message: "hunk at line 1 did not apply",
511 Code: ErrorCodeApplyFail,
512 Class: ErrorClassPatch,
513 },
514 },
515 {
516 name: "callbacks succeeding apply the diff",
517 tree: treeA,
518 diff: diffAB,
519 applyHunkCallback: func(*DiffHunk) (bool, error) { return true, nil },
520 applyDeltaCallback: func(*DiffDelta) (bool, error) { return true, nil },
521 expectedDiff: diffAB,
522 },
523 {

Callers

nothing calls this directly

Calls 12

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
seedTestRepoFunction · 0.85
addAndGetTreeFunction · 0.85
checkFatalFunction · 0.85
DefaultApplyOptionsFunction · 0.85
DiffTreeToTreeMethod · 0.80
ApplyToTreeMethod · 0.80
WriteTreeToMethod · 0.80
LookupTreeMethod · 0.80
ToBufMethod · 0.80
FreeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…