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

Method TestPatch

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

Source from the content-addressed store, hash-verified

127}
128
129func (s *SuiteCommit) TestPatch(c *C) {
130 from := s.commit(c, plumbing.NewHash("918c48b83bd081e863dbe1b80f8998f058cd8294"))
131 to := s.commit(c, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
132
133 patch, err := from.Patch(to)
134 c.Assert(err, IsNil)
135
136 buf := bytes.NewBuffer(nil)
137 err = patch.Encode(buf)
138 c.Assert(err, IsNil)
139
140 c.Assert(buf.String(), Equals, `diff --git a/vendor/foo.go b/vendor/foo.go
141new file mode 100644
142index 0000000000000000000000000000000000000000..9dea2395f5403188298c1dabe8bdafe562c491e3
143--- /dev/null
144+++ b/vendor/foo.go
145@@ -0,0 +1,7 @@
146+package main
147+
148+import "fmt"
149+
150+func main() {
151+ fmt.Println("Hello, playground")
152+}
153`)
154 c.Assert(buf.String(), Equals, patch.String())
155
156 from = s.commit(c, plumbing.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47"))
157 to = s.commit(c, plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9"))
158
159 patch, err = from.Patch(to)
160 c.Assert(err, IsNil)
161
162 buf.Reset()
163 err = patch.Encode(buf)
164 c.Assert(err, IsNil)
165
166 c.Assert(buf.String(), Equals, `diff --git a/CHANGELOG b/CHANGELOG
167deleted file mode 100644
168index d3ff53e0564a9f87d8e84b6e28e5060e517008aa..0000000000000000000000000000000000000000
169--- a/CHANGELOG
170+++ /dev/null
171@@ -1 +0,0 @@
172-Initial changelog
173diff --git a/binary.jpg b/binary.jpg
174new file mode 100644
175index 0000000000000000000000000000000000000000..d5c0f4ab811897cadf03aec358ae60d21f91c50d
176Binary files /dev/null and b/binary.jpg differ
177`)
178
179 c.Assert(buf.String(), Equals, patch.String())
180}
181
182func (s *SuiteCommit) TestPatchContext(c *C) {
183 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