From 5aaaff525ec972a8575b09cb3dbdb95ea7e73100 Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Fri, 16 Sep 2022 20:48:01 -0300 Subject: [PATCH 1/4] Remove git no-single-branch flag --- components/content-service/pkg/git/git.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/content-service/pkg/git/git.go b/components/content-service/pkg/git/git.go index fc14e8ddfb4dd8..b4eacbebe9f22e 100644 --- a/components/content-service/pkg/git/git.go +++ b/components/content-service/pkg/git/git.go @@ -328,7 +328,7 @@ func (c *Client) Clone(ctx context.Context) (err error) { log.WithError(err).Error("cannot create clone location") } - args := []string{"--depth=1", "--no-single-branch", c.RemoteURI} + args := []string{"--depth=1", c.RemoteURI} for key, value := range c.Config { args = append(args, "--config") From 94d724a8e856ed5d0e39c7ba7745c56d8e41e14b Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Sun, 18 Sep 2022 11:23:36 -0300 Subject: [PATCH 2/4] Ensure git fetch process all content --- components/content-service/pkg/initializer/git.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/content-service/pkg/initializer/git.go b/components/content-service/pkg/initializer/git.go index 2eade19f4cb469..1eb23e72d381a2 100644 --- a/components/content-service/pkg/initializer/git.go +++ b/components/content-service/pkg/initializer/git.go @@ -84,8 +84,16 @@ func (ws *GitInitializer) Run(ctx context.Context, mappings []archive.IDMapping) Err: fmt.Errorf("Access denied. Please check that Gitpod was given permission to access the repository"), } } + + return err } - return err + + err = ws.Git(ctx, "config", "--replace-all", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*") + if err != nil { + log.WithError(err).WithField("location", ws.Location).Error("cannot configure fecth behavior") + } + + return nil } onGitCloneFailure := func(e error, d time.Duration) { if err := os.RemoveAll(ws.Location); err != nil { From 3671d94396f4f17f71f94d3c4d5e76340ad2f12b Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Mon, 19 Sep 2022 10:53:52 -0300 Subject: [PATCH 3/4] Fetch before checkout --- components/content-service/pkg/initializer/git.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/content-service/pkg/initializer/git.go b/components/content-service/pkg/initializer/git.go index 1eb23e72d381a2..97c4fa6fdc7d17 100644 --- a/components/content-service/pkg/initializer/git.go +++ b/components/content-service/pkg/initializer/git.go @@ -170,14 +170,14 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) { switch ws.TargetMode { case RemoteBranch: // check remote branch exists before git checkout - gitout, err := ws.Client.GitWithOutput(ctx, nil, "ls-remote", "origin", ws.CloneTarget) + gitout, err := ws.GitWithOutput(ctx, nil, "ls-remote", "origin", ws.CloneTarget) if err != nil || len(gitout) == 0 { log.WithError(err).WithField("remoteURI", ws.RemoteURI).WithField("branch", ws.CloneTarget).Error("Remote branch doesn't exist.") return err } - // create local branch based on specific remote branch - if err := ws.Git(ctx, "checkout", "-B", ws.CloneTarget, "origin/"+ws.CloneTarget); err != nil { - log.WithError(err).WithField("remoteURI", ws.RemoteURI).WithField("branch", ws.CloneTarget).Error("Cannot checkout remote branch.") + + if err := ws.Git(ctx, "switch", "-C", ws.CloneTarget); err != nil { + log.WithError(err).WithField("remoteURI", ws.RemoteURI).WithField("branch", ws.CloneTarget).Error("Cannot fetch remote branch") return err } case LocalBranch: @@ -194,7 +194,7 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) { } // checkout specific commit - if err := ws.Git(ctx, "checkout", ws.CloneTarget); err != nil { + if err := ws.Git(ctx, "switch", "-C", ws.CloneTarget); err != nil { return err } default: From da4a8f1000cd920925ff2b190e0b6c0c6bfe015c Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Wed, 21 Sep 2022 18:46:06 -0300 Subject: [PATCH 4/4] Update integration test --- test/tests/workspace/contexts_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/workspace/contexts_test.go b/test/tests/workspace/contexts_test.go index 5e30ccc42a6c43..b61054a30d1c1e 100644 --- a/test/tests/workspace/contexts_test.go +++ b/test/tests/workspace/contexts_test.go @@ -51,7 +51,7 @@ func TestGitHubContexts(t *testing.T) { Name: "open tag", ContextURL: "github.com/gitpod-io/gitpod-test-repo/tree/integration-test-context-tag", WorkspaceRoot: "/workspace/gitpod-test-repo", - ExpectedBranch: "HEAD", + ExpectedBranch: "a89cab1135a2d05901ca3021d1608f24a0400932", }, { Name: "Git LFS support",