Skip to content

Commit

Permalink
feat(git): added commit hash support to git.ref (#9430)
Browse files Browse the repository at this point in the history
  • Loading branch information
idsulik authored Aug 29, 2024
1 parent 01bf561 commit d8ca62c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/skaffold/git/gitutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,22 @@ func syncRepo(ctx context.Context, g Config, opts config.SkaffoldOptions) (strin
return "", SyncDisabledErr(g, repoCacheDir)
}
if _, err := r.Run(ctx, "clone", g.RepoCloneURI, fmt.Sprintf("./%s", hash), "--branch", ref, "--depth", "1"); err != nil {
return "", fmt.Errorf("failed to clone repo: %w", err)
if strings.Contains(err.Error(), "Could not find remote branch") {
if _, err := r.Run(ctx, "clone", g.RepoCloneURI, fmt.Sprintf("./%s", hash), "--depth", "1"); err != nil {
return "", fmt.Errorf("failed to clone repo: %w", err)
}

r.Dir = repoCacheDir
if _, err := r.Run(ctx, "checkout", ref); err != nil {
if rmErr := os.RemoveAll(repoCacheDir); rmErr != nil {
err = fmt.Errorf("failed to remove repo cache dir: %w", rmErr)
}

return "", fmt.Errorf("failed to checkout commit: %w", err)
}
} else {
return "", fmt.Errorf("failed to clone repo: %w", err)
}
}
} else {
r.Dir = repoCacheDir
Expand Down

0 comments on commit d8ca62c

Please sign in to comment.