Skip to content

[supervisor] Check if git repository is shallow before running --unshallow #10993

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

Merged
merged 1 commit into from
Jun 29, 2022
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
23 changes: 23 additions & 0 deletions components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 == "" {
Expand Down