diff --git a/components/content-service/pkg/initializer/git.go b/components/content-service/pkg/initializer/git.go index 04d7676e56048c..22cc9806c79d1f 100644 --- a/components/content-service/pkg/initializer/git.go +++ b/components/content-service/pkg/initializer/git.go @@ -140,19 +140,26 @@ func (ws *GitInitializer) Run(ctx context.Context, mappings []archive.IDMapping) res, _ = cmd.CombinedOutput() log.Infof("[0] ls -al %s: %v", ws.Location+"/.git/", string(res)) } + if err := ws.realizeCloneTarget(ctx); err != nil { return src, xerrors.Errorf("git initializer clone: %w", err) } + + cmd := exec.Command("ls", "-al", ws.Location+"/.git/") + res, _ := cmd.CombinedOutput() + log.Infof("[1] ls -al %s: %v", ws.Location+"/.git/", string(res)) + if err := ws.UpdateRemote(ctx); err != nil { return src, xerrors.Errorf("git initializer updateRemote: %w", err) } + if err := ws.UpdateSubmodules(ctx); err != nil { log.WithError(err).Warn("error while updating submodules - continuing") } - cmd := exec.Command("ls", "-al", ws.Location+"/.git/") - res, _ := cmd.CombinedOutput() - log.Infof("[1] ls -al %s: %v", ws.Location+"/.git/", string(res)) + cmd = exec.Command("ls", "-al", ws.Location+"/.git/") + res, _ = cmd.CombinedOutput() + log.Infof("[2] ls -al %s: %v", ws.Location+"/.git/", string(res)) log.WithField("stage", "init").WithField("location", ws.Location).Debug("Git operations complete") return @@ -181,11 +188,21 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) { log.WithError(err).WithField("remoteURI", ws.RemoteURI).WithField("branch", ws.CloneTarget).Error("Remote branch doesn't exist.") return err } + + cmd := exec.Command("ls", "-al", ws.Location+"/.git/") + res, _ := cmd.CombinedOutput() + log.Infof("[realizeCloneTarget][0] ls -al %s: %v", ws.Location+"/.git/", string(res)) + // 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.") return err } + + cmd = exec.Command("ls", "-al", ws.Location+"/.git/") + res, _ = cmd.CombinedOutput() + log.Infof("[realizeCloneTarget][1] ls -al %s: %v", ws.Location+"/.git/", string(res)) + case LocalBranch: // checkout local branch based on remote HEAD if err := ws.Git(ctx, "checkout", "-B", ws.CloneTarget, "origin/HEAD", "--no-track"); err != nil { @@ -219,11 +236,11 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) { } func checkGitStatus(err error) error { - if err != nil { - if strings.Contains(err.Error(), "The requested URL returned error: 524") { - return fmt.Errorf("Git clone returned HTTP status 524 (see https://gitlab.com/gitlab-com/gl-infra/reliability/-/issues/8475). Please try restarting your workspace") - } + if err == nil { + return nil + } + if strings.Contains(err.Error(), "The requested URL returned error: 524") { + return fmt.Errorf("Git clone returned HTTP status 524 (see https://gitlab.com/gitlab-com/gl-infra/reliability/-/issues/8475). Please try restarting your workspace") } - return err }