From dd21a39c806452e817a7dd7eee4799abcefbf4f2 Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Mon, 19 Sep 2022 10:53:52 -0300 Subject: [PATCH] Fetch before checkout --- components/content-service/pkg/initializer/git.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/content-service/pkg/initializer/git.go b/components/content-service/pkg/initializer/git.go index 1eb23e72d381a2..6a21dabecb320c 100644 --- a/components/content-service/pkg/initializer/git.go +++ b/components/content-service/pkg/initializer/git.go @@ -175,6 +175,12 @@ 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 } + + if err := ws.Git(ctx, "fetch", "origin/"+ws.CloneTarget); err != nil { + log.WithError(err).WithField("remoteURI", ws.RemoteURI).WithField("branch", ws.CloneTarget).Error("Cannot fetch remote branch") + 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.")