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

Function TestDiffTreeToTree

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

Source from the content-addressed store, hash-verified

66}
67
68func TestDiffTreeToTree(t *testing.T) {
69 t.Parallel()
70 repo := createTestRepo(t)
71 defer cleanupTestRepo(t, repo)
72
73 originalTree, newTree := createTestTrees(t, repo)
74
75 callbackInvoked := false
76 opts := DiffOptions{
77 NotifyCallback: func(diffSoFar *Diff, delta DiffDelta, matchedPathSpec string) error {
78 callbackInvoked = true
79 return nil
80 },
81 OldPrefix: "x1/",
82 NewPrefix: "y1/",
83 }
84
85 diff, err := repo.DiffTreeToTree(originalTree, newTree, &opts)
86 checkFatal(t, err)
87 if !callbackInvoked {
88 t.Fatal("callback not invoked")
89 }
90
91 if diff == nil {
92 t.Fatal("no diff returned")
93 }
94
95 files := make([]string, 0)
96 hunks := make([]DiffHunk, 0)
97 lines := make([]DiffLine, 0)
98 patches := make([]string, 0)
99 err = diff.ForEach(func(file DiffDelta, progress float64) (DiffForEachHunkCallback, error) {
100 patch, err := diff.Patch(len(patches))
101 if err != nil {
102 return nil, err
103 }
104 defer patch.Free()
105 patchStr, err := patch.String()
106 if err != nil {
107 return nil, err
108 }
109 patches = append(patches, patchStr)
110
111 files = append(files, file.OldFile.Path)
112 return func(hunk DiffHunk) (DiffForEachLineCallback, error) {
113 hunks = append(hunks, hunk)
114 return func(line DiffLine) error {
115 lines = append(lines, line)
116 return nil
117 }, nil
118 }, nil
119 }, DiffDetailLines)
120
121 checkFatal(t, err)
122
123 if len(files) != 1 {
124 t.Fatal("Incorrect number of files in diff")
125 }

Callers

nothing calls this directly

Calls 13

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
createTestTreesFunction · 0.85
checkFatalFunction · 0.85
DiffTreeToTreeMethod · 0.80
PatchMethod · 0.80
StatsMethod · 0.80
InsertionsMethod · 0.80
DeletionsMethod · 0.80
FilesChangedMethod · 0.80
FreeMethod · 0.65
ForEachMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…