Skip to content

Commit 4aa614d

Browse files
yujunzalexmt
andauthored
fix: fetch revision only then fallback to default refspec (#5605)
* fix: fallback to fetch default only on error Ignoring commit SHA breaks gerrit when the commit is not merged Signed-off-by: Yujun Zhang <yujunz@nvidia.com> * revert util/git/client.go changes Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com> Co-authored-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
1 parent 6abccea commit 4aa614d

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

reposerver/repository/repository.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,25 +1583,25 @@ func checkoutRevision(gitClient git.Client, revision string) error {
15831583
return status.Errorf(codes.Internal, "Failed to initialize git repo: %v", err)
15841584
}
15851585

1586-
// Some git providers don't support fetching commit sha
1587-
if revision != "" && !git.IsCommitSHA(revision) && !git.IsTruncatedCommitSHA(revision) {
1588-
err = gitClient.Fetch(revision)
1589-
if err != nil {
1590-
return status.Errorf(codes.Internal, "Failed to fetch %s: %v", revision, err)
1591-
}
1592-
err = gitClient.Checkout("FETCH_HEAD")
1593-
if err != nil {
1594-
return status.Errorf(codes.Internal, "Failed to checkout FETCH_HEAD: %v", err)
1595-
}
1596-
} else {
1586+
err = gitClient.Fetch(revision)
1587+
1588+
if err != nil {
1589+
log.Infof("Failed to fetch revision %s: %v", revision, err)
1590+
log.Infof("Fallback to fetch default")
15971591
err = gitClient.Fetch("")
15981592
if err != nil {
1599-
return status.Errorf(codes.Internal, "Failed to fetch %s: %v", revision, err)
1593+
return status.Errorf(codes.Internal, "Failed to fetch default: %v", err)
16001594
}
16011595
err = gitClient.Checkout(revision)
16021596
if err != nil {
1603-
return status.Errorf(codes.Internal, "Failed to checkout %s: %v", revision, err)
1597+
return status.Errorf(codes.Internal, "Failed to checkout revision %s: %v", revision, err)
16041598
}
1599+
return err
1600+
}
1601+
1602+
err = gitClient.Checkout("FETCH_HEAD")
1603+
if err != nil {
1604+
return status.Errorf(codes.Internal, "Failed to checkout FETCH_HEAD: %v", err)
16051605
}
16061606

16071607
return err

0 commit comments

Comments
 (0)