Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit a39fae6

Browse files
authored
Merge pull request #783 from maguro/refspec-src
Fix RefSpec.Src()
2 parents 71e3741 + 87b7078 commit a39fae6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

config/refspec.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ func (s RefSpec) IsDelete() bool {
6262
// Src return the src side.
6363
func (s RefSpec) Src() string {
6464
spec := string(s)
65-
start := strings.Index(spec, refSpecForce) + 1
65+
66+
var start int
67+
if s.IsForceUpdate() {
68+
start = 1
69+
} else {
70+
start = 0
71+
}
6672
end := strings.Index(spec, refSpecSeparator)
6773

6874
return spec[start:end]

config/refspec_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,37 @@ func (s *RefSpecSuite) TestRefSpecSrc(c *C) {
6262
spec := RefSpec("refs/heads/*:refs/remotes/origin/*")
6363
c.Assert(spec.Src(), Equals, "refs/heads/*")
6464

65+
spec = RefSpec("+refs/heads/*:refs/remotes/origin/*")
66+
c.Assert(spec.Src(), Equals, "refs/heads/*")
67+
6568
spec = RefSpec(":refs/heads/master")
6669
c.Assert(spec.Src(), Equals, "")
70+
71+
spec = RefSpec("refs/heads/love+hate:refs/heads/love+hate")
72+
c.Assert(spec.Src(), Equals, "refs/heads/love+hate")
73+
74+
spec = RefSpec("+refs/heads/love+hate:refs/heads/love+hate")
75+
c.Assert(spec.Src(), Equals, "refs/heads/love+hate")
6776
}
6877

6978
func (s *RefSpecSuite) TestRefSpecMatch(c *C) {
7079
spec := RefSpec("refs/heads/master:refs/remotes/origin/master")
7180
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/foo")), Equals, false)
7281
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, true)
7382

83+
spec = RefSpec("+refs/heads/master:refs/remotes/origin/master")
84+
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/foo")), Equals, false)
85+
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, true)
86+
7487
spec = RefSpec(":refs/heads/master")
7588
c.Assert(spec.Match(plumbing.ReferenceName("")), Equals, true)
7689
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, false)
90+
91+
spec = RefSpec("refs/heads/love+hate:heads/love+hate")
92+
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/love+hate")), Equals, true)
93+
94+
spec = RefSpec("+refs/heads/love+hate:heads/love+hate")
95+
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/love+hate")), Equals, true)
7796
}
7897

7998
func (s *RefSpecSuite) TestRefSpecMatchGlob(c *C) {

0 commit comments

Comments
 (0)