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") diff --git a/components/content-service/pkg/initializer/git.go b/components/content-service/pkg/initializer/git.go index 2eade19f4cb469..97c4fa6fdc7d17 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 { @@ -162,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: @@ -186,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: 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",