diff --git a/components/supervisor/pkg/supervisor/supervisor.go b/components/supervisor/pkg/supervisor/supervisor.go index 95a3970d270a56..7d7cb946d7810d 100644 --- a/components/supervisor/pkg/supervisor/supervisor.go +++ b/components/supervisor/pkg/supervisor/supervisor.go @@ -357,6 +357,10 @@ func Run(options ...RunOption) { log.Debugf("unshallow of local repository took %v", time.Since(start)) }() + if !isShallowRepository(repoRoot, childProcEnvvars) { + return + } + cmd := runAsGitpodUser(exec.Command("git", "fetch", "--unshallow", "--tags")) cmd.Env = childProcEnvvars cmd.Dir = repoRoot @@ -392,6 +396,25 @@ func Run(options ...RunOption) { wg.Wait() } +func isShallowRepository(rootDir string, env []string) bool { + cmd := runAsGitpodUser(exec.Command("git", "rev-parse", "--is-shallow-repository")) + cmd.Env = env + cmd.Dir = rootDir + out, err := cmd.CombinedOutput() + if err != nil { + log.WithError(err).Error("unexpected error checking if git repository is shallow") + return true + } + + isShallow, err := strconv.ParseBool(strings.TrimSpace(string(out))) + if err != nil { + log.WithError(err).WithField("input", string(out)).Error("unexpected error parsing bool") + return true + } + + return isShallow +} + func installDotfiles(ctx context.Context, cfg *Config, tokenService *InMemoryTokenService, childProcEnvvars []string) { repo := cfg.DotfileRepo if repo == "" {