Skip to content

Commit 65384db

Browse files
aledbfroboquat
authored andcommitted
[supervisor] Check if git repository is shallow before running --unshallow
1 parent 6ee9b23 commit 65384db

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

components/supervisor/pkg/supervisor/supervisor.go

+23
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ func Run(options ...RunOption) {
357357
log.Debugf("unshallow of local repository took %v", time.Since(start))
358358
}()
359359

360+
if !isShallowRepository(repoRoot, childProcEnvvars) {
361+
return
362+
}
363+
360364
cmd := runAsGitpodUser(exec.Command("git", "fetch", "--unshallow", "--tags"))
361365
cmd.Env = childProcEnvvars
362366
cmd.Dir = repoRoot
@@ -392,6 +396,25 @@ func Run(options ...RunOption) {
392396
wg.Wait()
393397
}
394398

399+
func isShallowRepository(rootDir string, env []string) bool {
400+
cmd := runAsGitpodUser(exec.Command("git", "rev-parse", "--is-shallow-repository"))
401+
cmd.Env = env
402+
cmd.Dir = rootDir
403+
out, err := cmd.CombinedOutput()
404+
if err != nil {
405+
log.WithError(err).Error("unexpected error checking if git repository is shallow")
406+
return true
407+
}
408+
409+
isShallow, err := strconv.ParseBool(strings.TrimSpace(string(out)))
410+
if err != nil {
411+
log.WithError(err).WithField("input", string(out)).Error("unexpected error parsing bool")
412+
return true
413+
}
414+
415+
return isShallow
416+
}
417+
395418
func installDotfiles(ctx context.Context, cfg *Config, tokenService *InMemoryTokenService, childProcEnvvars []string) {
396419
repo := cfg.DotfileRepo
397420
if repo == "" {

0 commit comments

Comments
 (0)