Skip to content

Commit

Permalink
fix: fix fetching commit SHAs (#5312) (#5320)
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Matyushentsev <Alexander_Matyushentsev@intuit.com>
  • Loading branch information
Alexander Matyushentsev authored Jan 26, 2021
1 parent d8b545d commit d516f47
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
28 changes: 21 additions & 7 deletions reposerver/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,14 +1336,28 @@ func checkoutRevision(gitClient git.Client, revision string) error {
if err != nil {
return status.Errorf(codes.Internal, "Failed to initialize git repo: %v", err)
}
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)

// 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("")
if err != nil {
return status.Errorf(codes.Internal, "Failed to fetch %s: %v", revision, err)
}
err = gitClient.Checkout(revision)
if err != nil {
return status.Errorf(codes.Internal, "Failed to checkout %s: %v", revision, err)
}
}

return err
}

Expand Down
3 changes: 1 addition & 2 deletions util/git/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ func (m *nativeGitClient) IsLFSEnabled() bool {
// Fetch fetches latest updates from origin
func (m *nativeGitClient) Fetch(revision string) error {
var err error
// Some git providers don't support fetching commit sha
if revision != "" && !IsCommitSHA(revision) && !IsTruncatedCommitSHA(revision) {
if revision != "" {
err = m.runCredentialedCmd("git", "fetch", "origin", revision, "--tags", "--force")
} else {
err = m.runCredentialedCmd("git", "fetch", "origin", "--tags", "--force")
Expand Down

0 comments on commit d516f47

Please sign in to comment.