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

Function TestPatch

patch_test.go:8–38  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestPatch(t *testing.T) {
9 t.Parallel()
10 repo := createTestRepo(t)
11 defer cleanupTestRepo(t, repo)
12
13 _, originalTreeId := seedTestRepo(t, repo)
14 originalTree, err := repo.LookupTree(originalTreeId)
15
16 checkFatal(t, err)
17
18 _, newTreeId := updateReadme(t, repo, "file changed\n")
19
20 newTree, err := repo.LookupTree(newTreeId)
21 checkFatal(t, err)
22
23 opts := &DiffOptions{
24 OldPrefix: "a",
25 NewPrefix: "b",
26 }
27 diff, err := repo.DiffTreeToTree(originalTree, newTree, opts)
28 checkFatal(t, err)
29
30 patch, err := diff.Patch(0)
31 checkFatal(t, err)
32
33 patchStr, err := patch.String()
34 checkFatal(t, err)
35 if strings.Index(patchStr, "diff --git a/README b/README\nindex 257cc56..820734a 100644\n--- a/README\n+++ b/README\n@@ -1 +1 @@\n-foo\n+file changed") == -1 {
36 t.Fatalf("patch was bad")
37 }
38}

Callers

nothing calls this directly

Calls 10

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
seedTestRepoFunction · 0.85
checkFatalFunction · 0.85
updateReadmeFunction · 0.85
LookupTreeMethod · 0.80
DiffTreeToTreeMethod · 0.80
PatchMethod · 0.80
StringMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…