aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object/commit_test.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-07-10 11:34:51 +0200
committerGitHub <noreply@github.com>2018-07-10 11:34:51 +0200
commit3bd5e82b2512d85becae9677fa06b5a973fd4cfb (patch)
tree7b5aa42ef1b86540f0e30ab6e79aa0772e5986a7 /plumbing/object/commit_test.go
parent8ad72db0b7e1c03d9fad343890e469d5c3ed757b (diff)
parent9251ea764df3de13518f974635e76315b2b89e3e (diff)
downloadgo-git-3bd5e82b2512d85becae9677fa06b5a973fd4cfb.tar.gz
Merge pull request #874 from smola/patchcontextv4.5.0
plumbing: add context to allow cancel on diff/patch computing
Diffstat (limited to 'plumbing/object/commit_test.go')
-rw-r--r--plumbing/object/commit_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/plumbing/object/commit_test.go b/plumbing/object/commit_test.go
index 191b14d..996d481 100644
--- a/plumbing/object/commit_test.go
+++ b/plumbing/object/commit_test.go
@@ -2,6 +2,7 @@ package object
import (
"bytes"
+ "context"
"io"
"strings"
"time"
@@ -132,6 +133,59 @@ Binary files /dev/null and b/binary.jpg differ
c.Assert(buf.String(), Equals, patch.String())
}
+func (s *SuiteCommit) TestPatchContext(c *C) {
+ from := s.commit(c, plumbing.NewHash("918c48b83bd081e863dbe1b80f8998f058cd8294"))
+ to := s.commit(c, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+
+ patch, err := from.PatchContext(context.Background(), to)
+ c.Assert(err, IsNil)
+
+ buf := bytes.NewBuffer(nil)
+ err = patch.Encode(buf)
+ c.Assert(err, IsNil)
+
+ c.Assert(buf.String(), Equals, `diff --git a/vendor/foo.go b/vendor/foo.go
+new file mode 100644
+index 0000000000000000000000000000000000000000..9dea2395f5403188298c1dabe8bdafe562c491e3
+--- /dev/null
++++ b/vendor/foo.go
+@@ -0,0 +1,7 @@
++package main
++
++import "fmt"
++
++func main() {
++ fmt.Println("Hello, playground")
++}
+`)
+ c.Assert(buf.String(), Equals, patch.String())
+
+ from = s.commit(c, plumbing.NewHash("b8e471f58bcbca63b07bda20e428190409c2db47"))
+ to = s.commit(c, plumbing.NewHash("35e85108805c84807bc66a02d91535e1e24b38b9"))
+
+ patch, err = from.PatchContext(context.Background(), to)
+ c.Assert(err, IsNil)
+
+ buf.Reset()
+ err = patch.Encode(buf)
+ c.Assert(err, IsNil)
+
+ c.Assert(buf.String(), Equals, `diff --git a/CHANGELOG b/CHANGELOG
+deleted file mode 100644
+index d3ff53e0564a9f87d8e84b6e28e5060e517008aa..0000000000000000000000000000000000000000
+--- a/CHANGELOG
++++ /dev/null
+@@ -1 +0,0 @@
+-Initial changelog
+diff --git a/binary.jpg b/binary.jpg
+new file mode 100644
+index 0000000000000000000000000000000000000000..d5c0f4ab811897cadf03aec358ae60d21f91c50d
+Binary files /dev/null and b/binary.jpg differ
+`)
+
+ c.Assert(buf.String(), Equals, patch.String())
+}
+
func (s *SuiteCommit) TestCommitEncodeDecodeIdempotent(c *C) {
ts, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05-07:00")
c.Assert(err, IsNil)
@@ -363,3 +417,15 @@ sYyf9RfOnw/KUFAQbdtvLx3ikODQC+D3KBtuKI9ISHQfgw==
_, ok := e.Identities["Sunny <me@darkowlzz.space>"]
c.Assert(ok, Equals, true)
}
+
+func (s *SuiteCommit) TestPatchCancel(c *C) {
+ from := s.commit(c, plumbing.NewHash("918c48b83bd081e863dbe1b80f8998f058cd8294"))
+ to := s.commit(c, plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
+
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+ patch, err := from.PatchContext(ctx, to)
+ c.Assert(patch, IsNil)
+ c.Assert(err, ErrorMatches, "operation canceled")
+
+}