From 0d40b9cc847185fcccd376b34b39bbee0e04b8ea Mon Sep 17 00:00:00 2001 From: Camila Macedo <7708031+camilamacedo86@users.noreply.github.com> Date: Sun, 10 Aug 2025 00:39:02 +0100 Subject: [PATCH] alpha(update): add --squash, --preserve-path, --output-branch for PR-friendly upgrades MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change makes `kubebuilder alpha update` produce a PR-ready branch and a single squashed commit when requested, improving automation and review UX. Key changes ----------- • New `--squash` flag: - Snapshots the exact tree of the temporary merge branch into ONE commit on a stable branch: `kubebuilder-alpha-update-to-`. - Intended for opening/refreshing idempotent PRs. - Gracefully handles "no changes" (git commit exits 1 → treated as no-op). • New `--preserve-path` (repeatable): - When squashing, restore given paths from the base branch (e.g. `.github/workflows`) so CI/config files are kept as-is on the PR branch. • New `--output-branch`: - Overrides the default PR branch name created by `--squash`. • Commit message used by `--squash`: - `[kubebuilder-automated-update]: update scaffold from to ; (squashed 3-way merge)` • Behavior/ergonomics: - Without `--force`: stops on conflicts on the temporary merge branch. - With `--force`: commits conflict markers on the merge branch (automation-friendly). - After merge, still best-effort run: `make manifests generate fmt vet lint-fix`. Defaults / Compatibility ------------------------ - `--squash` is off by default (no behavior change unless opted-in). - `--from-branch` defaults to `main`. - `--preserve-path` is empty by default (no restores). - Safe to run on projects scaffolded with v4.5.0+ (uses `alpha generate`). Motivation ---------- Make upgrades PR-centric and automation-ready by producing a deterministic, reviewable branch and a single squashed commit that mirrors the merge result. Assisted-by: ChatGPT (OpenAI) Co-authored-by: Vitor Floriano --- .../src/reference/commands/alpha_update.md | 70 ++++++++++++-- pkg/cli/alpha/internal/update/update.go | 69 ++++++++++++++ pkg/cli/alpha/internal/update/update_test.go | 95 ++++++++++++++++++- pkg/cli/alpha/update.go | 73 +++++++++----- pkg/cli/alpha/update_test.go | 12 ++- test/e2e/alphaupdate/update_test.go | 80 +++++++++++----- 6 files changed, 337 insertions(+), 62 deletions(-) diff --git a/docs/book/src/reference/commands/alpha_update.md b/docs/book/src/reference/commands/alpha_update.md index b0d79dc54a1..16ea9cbe344 100644 --- a/docs/book/src/reference/commands/alpha_update.md +++ b/docs/book/src/reference/commands/alpha_update.md @@ -12,6 +12,7 @@ It uses a **3-way merge** so you do less manual work. The command creates these - **Merge**: result of merging **Original** into **Upgrade** (this is where conflicts appear) You can review and test the merge result before applying it to your main branch. +Optionally, use **`--squash`** to put the merge result into **one commit** on a stable output branch (great for PRs).