Skip to content

Commit a533f09

Browse files
committed
feat(git): added commit hash support to git.ref
1 parent f386e6c commit a533f09

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pkg/skaffold/git/gitutil.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,22 @@ func syncRepo(ctx context.Context, g Config, opts config.SkaffoldOptions) (strin
125125
return "", SyncDisabledErr(g, repoCacheDir)
126126
}
127127
if _, err := r.Run(ctx, "clone", g.RepoCloneURI, fmt.Sprintf("./%s", hash), "--branch", ref, "--depth", "1"); err != nil {
128-
return "", fmt.Errorf("failed to clone repo: %w", err)
128+
if strings.Contains(err.Error(), "Could not find remote branch") {
129+
if _, err := r.Run(ctx, "clone", g.RepoCloneURI, fmt.Sprintf("./%s", hash), "--depth", "1"); err != nil {
130+
return "", fmt.Errorf("failed to clone repo: %w", err)
131+
}
132+
133+
r.Dir = repoCacheDir
134+
if _, err := r.Run(ctx, "checkout", ref); err != nil {
135+
if err := os.RemoveAll(repoCacheDir); err != nil {
136+
err = fmt.Errorf("failed to remove repo cache dir: %w", err)
137+
}
138+
139+
return "", fmt.Errorf("failed to checkout commit: %w", err)
140+
}
141+
} else {
142+
return "", fmt.Errorf("failed to clone repo: %w", err)
143+
}
129144
}
130145
} else {
131146
r.Dir = repoCacheDir

0 commit comments

Comments
 (0)