diff --git a/components/content-service/pkg/git/git.go b/components/content-service/pkg/git/git.go index a22892672b3125..743053d3c3d5a4 100644 --- a/components/content-service/pkg/git/git.go +++ b/components/content-service/pkg/git/git.go @@ -264,17 +264,13 @@ func (c *Client) Clone(ctx context.Context) (err error) { log.WithError(err).Error() } - args := make([]string, 0) - args = append(args, c.RemoteURI) + args := []string{"--depth=1", "--no-single-branch", c.RemoteURI} for key, value := range c.Config { args = append(args, "--config") args = append(args, strings.TrimSpace(key)+"="+strings.TrimSpace(value)) } - // TODO(cw): re-introduce this when we have a better story for repo forking - // args = append(args, "--filter=blob:none") - args = append(args, ".") return c.Git(ctx, "clone", args...) diff --git a/components/content-service/pkg/initializer/git.go b/components/content-service/pkg/initializer/git.go index 40544e17cb6cf7..e51c497b5232a2 100644 --- a/components/content-service/pkg/initializer/git.go +++ b/components/content-service/pkg/initializer/git.go @@ -148,6 +148,13 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) { return err } } else if ws.TargetMode == RemoteCommit { + // We did a shallow clone before, hence need to fetch the commit we are about to check out. + // Because we don't want to make the "git fetch" mechanism in supervisor more complicated, + // we'll just fetch the 20 commits right away. + if err := ws.Git(ctx, "fetch", "origin", ws.CloneTarget, "--depth=20"); err != nil { + return err + } + // checkout specific commit if err := ws.Git(ctx, "checkout", ws.CloneTarget); err != nil { return err diff --git a/components/supervisor/pkg/supervisor/supervisor.go b/components/supervisor/pkg/supervisor/supervisor.go index 657c89fb70ee38..e851f19471b28e 100644 --- a/components/supervisor/pkg/supervisor/supervisor.go +++ b/components/supervisor/pkg/supervisor/supervisor.go @@ -311,6 +311,25 @@ func Run(options ...RunOption) { }() } + go func() { + <-cstate.ContentReady() + + start := time.Now() + defer func() { + log.Debugf("unshallow of local repository took %v", time.Since(start)) + }() + + cmd := runAsGitpodUser(exec.Command("git", "fetch", "--depth", "20")) + cmd.Env = buildChildProcEnv(cfg, nil) + cmd.Dir = cfg.RepoRoot + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil && !(err.Error() == "wait: no child processes" || err.Error() == "waitid: no child processes") { + log.WithError(err).Error("git fetch error") + } + }() + sigChan := make(chan os.Signal, 1) signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM) select {