MCPcopy Create free account
hub / github.com/go-git/go-git / TestPatch

Method TestPatch

plumbing/object/commit_test.go:85–136  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

83}
84
85func (s *SuiteCommit) TestPatch(c *C) {
86 from := s.commit(c, plumbing.NewHash("918c48b83bd081e863dbe1b80f8998f058cd8294"))
87 to := s.commit(c, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
88
89 patch, err := from.Patch(to)
90 c.Assert(err, IsNil)
91
92 buf := bytes.NewBuffer(nil)
93 err = patch.Encode(buf)
94 c.Assert(err, IsNil)
95
96 c.Assert(buf.String(), Equals, `diff --git a/vendor/foo.go b/vendor/foo.go
97new file mode 100644
98index 0000000000000000000000000000000000000000..9dea2395f5403188298c1dabe8bdafe562c491e3
99--- /dev/null
100+++ b/vendor/foo.go
101@@ -0,0 +1,7 @@
102+package main
103+
104+import "fmt"
105+
106+func main() {
107+ fmt.Println("Hello, playground")
108+}
109`)
110 c.Assert(buf.String(), Equals, patch.String())
111
112 from = s.commit(c, plumbing.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47"))
113 to = s.commit(c, plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9"))
114
115 patch, err = from.Patch(to)
116 c.Assert(err, IsNil)
117
118 buf.Reset()
119 err = patch.Encode(buf)
120 c.Assert(err, IsNil)
121
122 c.Assert(buf.String(), Equals, `diff --git a/CHANGELOG b/CHANGELOG
123deleted file mode 100644
124index d3ff53e0564a9f87d8e84b6e28e5060e517008aa..0000000000000000000000000000000000000000
125--- a/CHANGELOG
126+++ /dev/null
127@@ -1 +0,0 @@
128-Initial changelog
129diff --git a/binary.jpg b/binary.jpg
130new file mode 100644
131index 0000000000000000000000000000000000000000..d5c0f4ab811897cadf03aec358ae60d21f91c50d
132Binary files /dev/null and b/binary.jpg differ
133`)
134
135 c.Assert(buf.String(), Equals, patch.String())
136}
137
138func (s *SuiteCommit) TestPatchContext(c *C) {
139 from := s.commit(c, plumbing.NewHash("918c48b83bd081e863dbe1b80f8998f058cd8294"))

Callers

nothing calls this directly

Calls 6

NewHashFunction · 0.92
commitMethod · 0.80
EncodeMethod · 0.65
StringMethod · 0.65
PatchMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected