Skip to content

[content-service] Make prebuild initializer more robust #13956

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 1 commit into from
Oct 18, 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
7 changes: 0 additions & 7 deletions components/content-service/pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,6 @@ func (c *Client) Clone(ctx context.Context) (err error) {
return c.Git(ctx, "clone", args...)
}

// Fetch runs git fetch and prunes remote-tracking references as well as ALL LOCAL TAGS.
func (c *Client) Fetch(ctx context.Context) (err error) {
// we need to fetch with pruning to avoid issues like github.com/gitpod-io/gitpod/issues/7561.
// See https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt---prune for more details.
return c.Git(ctx, "fetch", "-p", "-P", "--tags", "-f")
}

// UpdateRemote performs a git fetch on the upstream remote URI
func (c *Client) UpdateRemote(ctx context.Context) (err error) {
//nolint:staticcheck,ineffassign
Expand Down
8 changes: 7 additions & 1 deletion components/content-service/pkg/initializer/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,13 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) {
ws.CloneTarget = defaultBranch
}

if err := ws.Git(ctx, "fetch", "--depth=1", "origin", ws.CloneTarget); err != nil {
// No need to prune here because we fetch the specific branch only. If we were to try and fetch everything,
// we might end up trying to fetch at tag/branch which has since been recreated. It's exactly the specific
// fetch wich prevents this situation.
//
// We don't recurse submodules because callers realizeCloneTarget() are expected to update submodules explicitly,
// and deal with any error appropriately (i.e. emit a warning rather than fail).
if err := ws.Git(ctx, "fetch", "--depth=1", "origin", "--recurse-submodules=no", ws.CloneTarget); err != nil {
log.WithError(err).WithField("remoteURI", ws.RemoteURI).WithField("branch", ws.CloneTarget).Error("Cannot fetch remote branch")
return err
}
Expand Down
7 changes: 3 additions & 4 deletions components/content-service/pkg/initializer/prebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,14 @@ func runGitInit(ctx context.Context, gInit *GitInitializer) (err error) {
}
didStash := !strings.Contains(string(out), "No local changes to save")

err = gInit.Fetch(ctx)
err = checkGitStatus(err)
err = checkGitStatus(gInit.realizeCloneTarget(ctx))
if err != nil {
return xerrors.Errorf("prebuild initializer: %w", err)
}

err = gInit.realizeCloneTarget(ctx)
err = gInit.UpdateSubmodules(ctx)
if err != nil {
return xerrors.Errorf("prebuild initializer: %w", err)
log.WithError(err).Warn("error while updating submodules from prebuild initializer - continuing")
}

// If any of these cleanup operations fail that's no reason to fail ws initialization.
Expand Down