Skip to content

Commit 4a91eb5

Browse files
committed
Switch to git shallow clone and add unshallow feature
1 parent 21fda09 commit 4a91eb5

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

components/content-service/pkg/git/git.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,16 @@ func (c *Client) Clone(ctx context.Context) (err error) {
264264
log.WithError(err).Error()
265265
}
266266

267-
args := make([]string, 0)
268-
args = append(args, c.RemoteURI)
267+
args := []string{"--depth=1", "--no-single-branch", c.RemoteURI}
269268

270269
for key, value := range c.Config {
271270
args = append(args, "--config")
272271
args = append(args, strings.TrimSpace(key)+"="+strings.TrimSpace(value))
273272
}
274273

275-
// TODO(cw): re-introduce this when we have a better story for repo forking
276-
// args = append(args, "--filter=blob:none")
277-
278274
args = append(args, ".")
279275

276+
log.Infof("Git clone: %v", args)
280277
return c.Git(ctx, "clone", args...)
281278
}
282279

components/gitpod-protocol/data/gitpod-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@
210210
"experimentalNetwork": {
211211
"type": "boolean",
212212
"description": "Experimental network configuration in workspaces"
213+
},
214+
"unshallowAfter": {
215+
"type": "string",
216+
"description": "Enable git unshallow after the initial load of the workspace"
213217
}
214218
},
215219
"additionalProperties": false

components/gitpod-protocol/src/protocol.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,14 @@ export interface WorkspaceConfig {
564564
/** tailscale demo */
565565
experimentalNetwork?: boolean;
566566

567+
/**
568+
* Enable git unshallow after the initial load of the workspace
569+
* Valid time units are "s", "m", "h". Example: 30s
570+
*
571+
* Minimum value: 60s
572+
* */
573+
unshallowAfter?: string
574+
567575
/**
568576
* Where the config object originates from.
569577
*

components/server/src/workspace/workspace-starter.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,13 @@ export class WorkspaceStarter {
659659
envvars.push(useNetnsVar);
660660
}
661661

662+
if (workspace.config.unshallowAfter) {
663+
const unshallow = new EnvironmentVariable();
664+
unshallow.setName("GIT_UNSHALLOW_AFTER");
665+
unshallow.setValue(workspace.config.unshallowAfter);
666+
envvars.push(unshallow);
667+
}
668+
662669
const createGitpodTokenPromise = (async () => {
663670
const scopes = this.createDefaultGitpodAPITokenScopes(workspace, instance);
664671
const token = crypto.randomBytes(30).toString('hex');

components/workspacekit/cmd/rings.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,39 @@ var ring1Cmd = &cobra.Command{
546546
}
547547
}()
548548

549+
if unshallowAfter := os.Getenv("GIT_UNSHALLOW_AFTER"); unshallowAfter != "" {
550+
log.WithField("unshallowAfter", unshallowAfter).Info("workspace configured with unshallow feature")
551+
552+
t, err := time.ParseDuration(unshallowAfter)
553+
if err != nil {
554+
log.WithError(err).Error("failed to parse GIT_UNSHALLOW_AFTER env variable")
555+
} else {
556+
// no less than a minute before running unshallow
557+
oneMinute := 1 * time.Minute
558+
if t < oneMinute {
559+
t = oneMinute
560+
}
561+
562+
go func() {
563+
log.Infof("Waiting %v before running the unshallow script", t)
564+
<-time.After(t)
565+
566+
start := time.Now()
567+
defer func() {
568+
log.Infof("unshallow of local repository took %v", time.Since(start))
569+
}()
570+
571+
cmd := exec.Command("/bin/bash", "-c", `if git fetch --help | grep -c -- '--unshallow'; then git fetch --unshallow; else git fetch --depth 1000000000; fi`)
572+
cmd.Env = os.Environ()
573+
cmd.Dir = os.Getenv("GITPOD_REPO_ROOT")
574+
out, err := cmd.CombinedOutput()
575+
if err != nil {
576+
log.WithError(err).WithField("reason", string(out)).Error("cannot run unshallow")
577+
}
578+
}()
579+
}
580+
}
581+
549582
err = cmd.Wait()
550583
if err != nil {
551584
if eerr, ok := err.(*exec.ExitError); ok {

0 commit comments

Comments
 (0)