Skip to content

Commit 2365ba4

Browse files
committed
[content-init] Make 'GitInitializer.realizeCloneTarget' always checkout the correct revision, even for older clones (e.g. incremental prebuild)
We previously assumed that a prebuild snapshot holds the latest commits, but this changes with incremental prebuilds (where an older prebuild doesn't have the latest commits, but 'origin' does). Fixes #4167 (comment)
1 parent d1ab495 commit 2365ba4

File tree

1 file changed

+8
-4
lines changed
  • components/content-service/pkg/initializer

1 file changed

+8
-4
lines changed

components/content-service/pkg/initializer/git.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,25 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) {
9393

9494
// checkout branch
9595
if ws.TargetMode == RemoteBranch {
96-
// create local branch based on remote
96+
// create local branch based on specific remote branch
9797
if err := ws.Git(ctx, "checkout", "-B", ws.CloneTarget, "origin/"+ws.CloneTarget); err != nil {
9898
return err
9999
}
100100
} else if ws.TargetMode == LocalBranch {
101-
if err := ws.Git(ctx, "checkout", "-b", ws.CloneTarget); err != nil {
101+
// checkout local branch based on remote HEAD
102+
if err := ws.Git(ctx, "checkout", "-B", ws.CloneTarget, "origin/HEAD"); err != nil {
102103
return err
103104
}
104105
} else if ws.TargetMode == RemoteCommit {
105106
// checkout specific commit
106107
if err := ws.Git(ctx, "checkout", ws.CloneTarget); err != nil {
107108
return err
108109
}
109-
} else { //nolint:staticcheck
110-
// nothing to do - we're already on the remote branch
110+
} else {
111+
// update to remote HEAD
112+
if err := ws.Git(ctx, "reset", "--hard", "origin/HEAD"); err != nil {
113+
return err
114+
}
111115
}
112116
return nil
113117
}

0 commit comments

Comments
 (0)