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

Fix RefSpec.Src() #783

Merged
merged 2 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion config/refspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions config/refspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func (s *RefSpecSuite) TestRefSpecSrc(c *C) {

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")
}

func (s *RefSpecSuite) TestRefSpecMatch(c *C) {
Expand All @@ -74,6 +77,9 @@ func (s *RefSpecSuite) TestRefSpecMatch(c *C) {
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)
}

func (s *RefSpecSuite) TestRefSpecMatchGlob(c *C) {
Expand Down