aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/refspec.go8
-rw-r--r--config/refspec_test.go19
2 files changed, 26 insertions, 1 deletions
diff --git a/config/refspec.go b/config/refspec.go
index af7e732..c9b9d52 100644
--- a/config/refspec.go
+++ b/config/refspec.go
@@ -62,7 +62,13 @@ func (s RefSpec) IsDelete() bool {
// Src return the src side.
func (s RefSpec) Src() string {
spec := string(s)
- start := strings.Index(spec, refSpecForce) + 1
+
+ var start int
+ if s.IsForceUpdate() {
+ start = 1
+ } else {
+ start = 0
+ }
end := strings.Index(spec, refSpecSeparator)
return spec[start:end]
diff --git a/config/refspec_test.go b/config/refspec_test.go
index 5ee6108..675e075 100644
--- a/config/refspec_test.go
+++ b/config/refspec_test.go
@@ -62,8 +62,17 @@ func (s *RefSpecSuite) TestRefSpecSrc(c *C) {
spec := RefSpec("refs/heads/*:refs/remotes/origin/*")
c.Assert(spec.Src(), Equals, "refs/heads/*")
+ spec = RefSpec("+refs/heads/*:refs/remotes/origin/*")
+ c.Assert(spec.Src(), Equals, "refs/heads/*")
+
spec = RefSpec(":refs/heads/master")
c.Assert(spec.Src(), Equals, "")
+
+ spec = RefSpec("refs/heads/love+hate:refs/heads/love+hate")
+ c.Assert(spec.Src(), Equals, "refs/heads/love+hate")
+
+ spec = RefSpec("+refs/heads/love+hate:refs/heads/love+hate")
+ c.Assert(spec.Src(), Equals, "refs/heads/love+hate")
}
func (s *RefSpecSuite) TestRefSpecMatch(c *C) {
@@ -71,9 +80,19 @@ func (s *RefSpecSuite) TestRefSpecMatch(c *C) {
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/foo")), Equals, false)
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, true)
+ spec = RefSpec("+refs/heads/master:refs/remotes/origin/master")
+ c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/foo")), Equals, false)
+ c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, true)
+
spec = RefSpec(":refs/heads/master")
c.Assert(spec.Match(plumbing.ReferenceName("")), Equals, true)
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, false)
+
+ spec = RefSpec("refs/heads/love+hate:heads/love+hate")
+ c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/love+hate")), Equals, true)
+
+ spec = RefSpec("+refs/heads/love+hate:heads/love+hate")
+ c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/love+hate")), Equals, true)
}
func (s *RefSpecSuite) TestRefSpecMatchGlob(c *C) {