aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArieh Schneier <15041913+AriehSchneier@users.noreply.github.com>2023-05-03 14:01:24 +1000
committerArieh Schneier <15041913+AriehSchneier@users.noreply.github.com>2023-05-03 14:01:24 +1000
commita4b11abc55bf88fbd07a00a5985a34750bee1d72 (patch)
tree167143e089189eac69cdcaadccbed7b400419dc5
parent0542a302c2be7ed7de276411f7e20b87309734b9 (diff)
downloadgo-git-a4b11abc55bf88fbd07a00a5985a34750bee1d72.tar.gz
git: fix cloning with branch name
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
-rw-r--r--repository.go16
-rw-r--r--repository_test.go10
2 files changed, 23 insertions, 3 deletions
diff --git a/repository.go b/repository.go
index e009c5d..be5f140 100644
--- a/repository.go
+++ b/repository.go
@@ -1012,9 +1012,21 @@ func (r *Repository) fetchAndUpdateReferences(
return nil, err
}
- resolvedRef, err := storer.ResolveReference(remoteRefs, ref)
+ var resolvedRef *plumbing.Reference
+ // return error from checking the raw ref passed in
+ var rawRefError error
+ for _, rule := range append([]string{"%s"}, plumbing.RefRevParseRules...) {
+ resolvedRef, err = storer.ResolveReference(remoteRefs, plumbing.ReferenceName(fmt.Sprintf(rule, ref)))
+
+ if err == nil {
+ break
+ } else if rawRefError == nil {
+ rawRefError = err
+ }
+ }
+
if err != nil {
- return nil, err
+ return nil, rawRefError
}
refsUpdated, err := r.updateReferences(remote.c.Fetch, resolvedRef)
diff --git a/repository_test.go b/repository_test.go
index ed3e7e6..0080a83 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -1020,6 +1020,14 @@ func (s *RepositorySuite) TestCloneConfig(c *C) {
}
func (s *RepositorySuite) TestCloneSingleBranchAndNonHEAD(c *C) {
+ s.testCloneSingleBranchAndNonHEADReference(c, "refs/heads/branch")
+}
+
+func (s *RepositorySuite) TestCloneSingleBranchAndNonHEADAndNonFull(c *C) {
+ s.testCloneSingleBranchAndNonHEADReference(c, "branch")
+}
+
+func (s *RepositorySuite) testCloneSingleBranchAndNonHEADReference(c *C, ref string) {
r, _ := Init(memory.NewStorage(), nil)
head, err := r.Head()
@@ -1028,7 +1036,7 @@ func (s *RepositorySuite) TestCloneSingleBranchAndNonHEAD(c *C) {
err = r.clone(context.Background(), &CloneOptions{
URL: s.GetBasicLocalRepositoryURL(),
- ReferenceName: plumbing.ReferenceName("refs/heads/branch"),
+ ReferenceName: plumbing.ReferenceName(ref),
SingleBranch: true,
})