Skip to content

Commit 5063d1b

Browse files
authored
fix: only use repo mode in cache probe mode (#294)
1 parent 2b457fe commit 5063d1b

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

envbuilder.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -863,35 +863,35 @@ func RunCacheProbe(ctx context.Context, opts options.Options) (v1.Image, error)
863863
var fallbackErr error
864864
var cloned bool
865865
if opts.GitURL != "" {
866-
cloneOpts, err := git.CloneOptionsFromOptions(opts)
867-
if err != nil {
868-
return nil, fmt.Errorf("git clone options: %w", err)
869-
}
866+
// In cache probe mode we should only attempt to clone the full
867+
// repository if remote repo build mode isn't enabled.
868+
if !opts.RemoteRepoBuildMode {
869+
cloneOpts, err := git.CloneOptionsFromOptions(opts)
870+
if err != nil {
871+
return nil, fmt.Errorf("git clone options: %w", err)
872+
}
870873

871-
endStage := startStage("📦 Cloning %s to %s...",
872-
newColor(color.FgCyan).Sprintf(opts.GitURL),
873-
newColor(color.FgCyan).Sprintf(cloneOpts.Path),
874-
)
874+
endStage := startStage("📦 Cloning %s to %s...",
875+
newColor(color.FgCyan).Sprintf(opts.GitURL),
876+
newColor(color.FgCyan).Sprintf(cloneOpts.Path),
877+
)
875878

876-
w := git.ProgressWriter(func(line string) { opts.Logger(log.LevelInfo, "#%d: %s", stageNumber, line) })
877-
defer w.Close()
878-
cloneOpts.Progress = w
879+
w := git.ProgressWriter(func(line string) { opts.Logger(log.LevelInfo, "#%d: %s", stageNumber, line) })
880+
defer w.Close()
881+
cloneOpts.Progress = w
879882

880-
cloned, fallbackErr = git.CloneRepo(ctx, cloneOpts)
881-
if fallbackErr == nil {
882-
if cloned {
883-
endStage("📦 Cloned repository!")
883+
cloned, fallbackErr = git.CloneRepo(ctx, cloneOpts)
884+
if fallbackErr == nil {
885+
if cloned {
886+
endStage("📦 Cloned repository!")
887+
} else {
888+
endStage("📦 The repository already exists!")
889+
}
884890
} else {
885-
endStage("📦 The repository already exists!")
891+
opts.Logger(log.LevelError, "Failed to clone repository: %s", fallbackErr.Error())
892+
opts.Logger(log.LevelError, "Falling back to the default image...")
886893
}
887894
} else {
888-
opts.Logger(log.LevelError, "Failed to clone repository: %s", fallbackErr.Error())
889-
opts.Logger(log.LevelError, "Falling back to the default image...")
890-
}
891-
892-
// Always clone the repo in remote repo build mode into a location that
893-
// we control that isn't affected by the users changes.
894-
if opts.RemoteRepoBuildMode {
895895
cloneOpts, err := git.CloneOptionsFromOptions(opts)
896896
if err != nil {
897897
return nil, fmt.Errorf("git clone options: %w", err)

0 commit comments

Comments
 (0)