Skip to content

Switch to shallow git clone and add unshallow feature #6464

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 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions components/content-service/pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
7 changes: 7 additions & 0 deletions components/content-service/pkg/initializer/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions components/supervisor/pkg/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down