Skip to content

Commit

Permalink
plumbing: Fix invalid reference name error while cloning branches con…
Browse files Browse the repository at this point in the history
…taining /- (#1257)

* plumbing: Fix invalid reference name error while cloning branches containing /-

* Tests
  • Loading branch information
varmakarthik12 authored Dec 20, 2024
1 parent 65f5e1a commit 62a77b7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions plumbing/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (r ReferenceName) Validate() error {

isBranch := r.IsBranch()
isTag := r.IsTag()
for _, part := range parts {
for i, part := range parts {
// rule 6
if len(part) == 0 {
return ErrInvalidReferenceName
Expand All @@ -205,7 +205,7 @@ func (r ReferenceName) Validate() error {
return ErrInvalidReferenceName
}

if (isBranch || isTag) && strings.HasPrefix(part, "-") { // branches & tags can't start with -
if (isBranch || isTag) && strings.HasPrefix(part, "-") && (i == 2) { // branches & tags can't start with -
return ErrInvalidReferenceName
}
}
Expand Down
2 changes: 2 additions & 0 deletions plumbing/reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func (s *ReferenceSuite) TestValidReferenceNames(c *C) {
"refs/pulls/1/abc.123",
"refs/pulls",
"refs/-", // should this be allowed?
"refs/ab/-testing",
"refs/123-testing",
}
for _, v := range valid {
c.Assert(v.Validate(), IsNil)
Expand Down

0 comments on commit 62a77b7

Please sign in to comment.