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

Commit d873056

Browse files
maguroAlan Cabrera
authored andcommitted
Fix RefSpec.Src()
Previously, the Src() function was assuming there are no “+” characters in the refspec src and erroneously used the strings.Index() function to compute the start index of src in the refspec. This change now uses the IsForceUpdate() method to decide how to elide the force update token. Signed-off-by: Alan Cabrera <adc@toolazydogs.com>
1 parent ecda5c1 commit d873056

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ func (s *RefSpecSuite) TestRefSpecSrc(c *C) {
6464

6565
spec = RefSpec(":refs/heads/master")
6666
c.Assert(spec.Src(), Equals, "")
67+
68+
spec = RefSpec("refs/heads/love+hate:refs/heads/love+hate")
69+
c.Assert(spec.Src(), Equals, "refs/heads/love+hate")
6770
}
6871

6972
func (s *RefSpecSuite) TestRefSpecMatch(c *C) {
@@ -74,6 +77,9 @@ func (s *RefSpecSuite) TestRefSpecMatch(c *C) {
7477
spec = RefSpec(":refs/heads/master")
7578
c.Assert(spec.Match(plumbing.ReferenceName("")), Equals, true)
7679
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/master")), Equals, false)
80+
81+
spec = RefSpec("refs/heads/love+hate:heads/love+hate")
82+
c.Assert(spec.Match(plumbing.ReferenceName("refs/heads/love+hate")), Equals, true)
7783
}
7884

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

0 commit comments

Comments
 (0)