Skip to content

Commit

Permalink
fix: fetch revision only then fallback to default refspec (#5605)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
yujunz and alexmt authored Jan 28, 2022
1 parent 6abccea commit 4aa614d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1583,25 +1583,25 @@ func checkoutRevision(gitClient git.Client, revision string) error {
return status.Errorf(codes.Internal, "Failed to initialize git repo: %v", err)
}

// Some git providers don't support fetching commit sha
if revision != "" && !git.IsCommitSHA(revision) && !git.IsTruncatedCommitSHA(revision) {
err = gitClient.Fetch(revision)
if err != nil {
return status.Errorf(codes.Internal, "Failed to fetch %s: %v", revision, err)
}
err = gitClient.Checkout("FETCH_HEAD")
if err != nil {
return status.Errorf(codes.Internal, "Failed to checkout FETCH_HEAD: %v", err)
}
} else {
err = gitClient.Fetch(revision)

if err != nil {
log.Infof("Failed to fetch revision %s: %v", revision, err)
log.Infof("Fallback to fetch default")
err = gitClient.Fetch("")
if err != nil {
return status.Errorf(codes.Internal, "Failed to fetch %s: %v", revision, err)
return status.Errorf(codes.Internal, "Failed to fetch default: %v", err)
}
err = gitClient.Checkout(revision)
if err != nil {
return status.Errorf(codes.Internal, "Failed to checkout %s: %v", revision, err)
return status.Errorf(codes.Internal, "Failed to checkout revision %s: %v", revision, err)
}
return err
}

err = gitClient.Checkout("FETCH_HEAD")
if err != nil {
return status.Errorf(codes.Internal, "Failed to checkout FETCH_HEAD: %v", err)
}

return err
Expand Down

0 comments on commit 4aa614d

Please sign in to comment.