Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(git): added commit hash support to git.ref #9430

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading