Skip to content

Commit 62a77b7

Browse files
plumbing: Fix invalid reference name error while cloning branches containing /- (#1257)
* plumbing: Fix invalid reference name error while cloning branches containing /- * Tests
1 parent 65f5e1a commit 62a77b7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

plumbing/reference.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (r ReferenceName) Validate() error {
188188

189189
isBranch := r.IsBranch()
190190
isTag := r.IsTag()
191-
for _, part := range parts {
191+
for i, part := range parts {
192192
// rule 6
193193
if len(part) == 0 {
194194
return ErrInvalidReferenceName
@@ -205,7 +205,7 @@ func (r ReferenceName) Validate() error {
205205
return ErrInvalidReferenceName
206206
}
207207

208-
if (isBranch || isTag) && strings.HasPrefix(part, "-") { // branches & tags can't start with -
208+
if (isBranch || isTag) && strings.HasPrefix(part, "-") && (i == 2) { // branches & tags can't start with -
209209
return ErrInvalidReferenceName
210210
}
211211
}

plumbing/reference_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func (s *ReferenceSuite) TestValidReferenceNames(c *C) {
115115
"refs/pulls/1/abc.123",
116116
"refs/pulls",
117117
"refs/-", // should this be allowed?
118+
"refs/ab/-testing",
119+
"refs/123-testing",
118120
}
119121
for _, v := range valid {
120122
c.Assert(v.Validate(), IsNil)

0 commit comments

Comments
 (0)