Skip to content

[content-service] Remove git no-single-branch flag #13053

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 4 commits into from
Sep 22, 2022
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
2 changes: 1 addition & 1 deletion components/content-service/pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
20 changes: 14 additions & 6 deletions components/content-service/pkg/initializer/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @aledbf 👋 ,

question (non-blocking): how come some case statements ☝️ are logging errors and others do not? I ask because I'm not sure why there is variance.

It seems like we may want to log the errors in each case (especially because we're changing from checkout to switch), but I could also be being naive. I haven't opened this to see if the calling function logs the related error.

https://github.com/gitpod-io/gitpod/pull/13053/files#diff-c9626ddd8d63f48f858c8e81807c14008f5c4199bd41ba80a2981401111356f0R186

https://github.com/gitpod-io/gitpod/pull/13053/files#diff-c9626ddd8d63f48f858c8e81807c14008f5c4199bd41ba80a2981401111356f0R193

https://github.com/gitpod-io/gitpod/pull/13053/files#diff-c9626ddd8d63f48f858c8e81807c14008f5c4199bd41ba80a2981401111356f0R198

return err
}
default:
Expand Down
2 changes: 1 addition & 1 deletion test/tests/workspace/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down