Skip to content

Commit ec3d604

Browse files
authored
Merge pull request #5019 from camilamacedo86/enhance-targets-conf
✨ (alpha update) skip running make targets if Makefile has conflicts
2 parents 79a817b + 0c90467 commit ec3d604

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

pkg/cli/alpha/internal/update/update.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,26 @@ func runMakeTargets() {
451451
}
452452
}
453453

454+
// hasMakefileConflict returns true if the Makefile (or makefile) is in conflict.
455+
func hasMakefileConflict() bool {
456+
// Check unmerged entries for Makefile/makefile.
457+
out, err := exec.Command("git", "ls-files", "-u", "--", "Makefile", "makefile").Output()
458+
if err == nil && len(strings.TrimSpace(string(out))) > 0 {
459+
return true
460+
}
461+
462+
// Fallback: file content contains conflict markers.
463+
check := func(p string) bool {
464+
b, err := os.ReadFile(p)
465+
if err != nil {
466+
return false
467+
}
468+
s := string(b)
469+
return strings.Contains(s, "<<<<<<<") && strings.Contains(s, "=======") && strings.Contains(s, ">>>>>>>")
470+
}
471+
return check("Makefile") || check("makefile")
472+
}
473+
454474
// runAlphaGenerate executes the old Kubebuilder version's 'alpha generate' command
455475
// to create clean scaffolding in the ancestor branch. This uses the downloaded
456476
// binary with the original PROJECT file to recreate the project's initial state.
@@ -581,7 +601,11 @@ func (opts *Update) mergeOriginalToUpgrade() (bool, error) {
581601
}
582602

583603
// Best effort to run make targets to ensure the project is in a good state
584-
runMakeTargets()
604+
if hasMakefileConflict() {
605+
log.Warn("Skipping make targets because the Makefile has merge conflicts.")
606+
} else {
607+
runMakeTargets()
608+
}
585609

586610
// Step 4: Stage and commit
587611
if err := exec.Command("git", "add", "--all").Run(); err != nil {

0 commit comments

Comments
 (0)