Skip to content

Commit 6d293e7

Browse files
✨ (alpha update): Rename alpha update flag preserve-path to restore-path (#5026)
(chore): Rename alpha update flag preserve-path to restore-path Co-authored-by: Vitor Floriano <[email protected]>
1 parent 2fc27db commit 6d293e7

File tree

6 files changed

+24
-24
lines changed

6 files changed

+24
-24
lines changed

docs/book/src/reference/commands/alpha_update.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The command creates three temporary branches:
5050
`kubebuilder-update-from-<from-version>-to-<to-version>`.
5151
- You can change the behavior:
5252
- `--show-commits`: keep the full history.
53-
- `--preserve-path`: in squash mode, restore specific files (like CI configs) from your base branch.
53+
- `--restore-path`: in squash mode, restore specific files (like CI configs) from your base branch.
5454
- `--output-branch`: pick a custom branch name.
5555
- `--push`: push the result to `origin` automatically.
5656

@@ -89,8 +89,8 @@ Default squash but **preserve** CI/workflows from the base branch:
8989

9090
```shell
9191
kubebuilder alpha update --force \
92-
--preserve-path .github/workflows \
93-
--preserve-path docs
92+
--restore-path .github/workflows \
93+
--restore-path docs
9494
```
9595

9696
Use a custom output branch name:
@@ -140,8 +140,8 @@ make all
140140
| `--to-version` | Kubebuilder release to update **to** (e.g., `v4.7.0`). If unset, defaults to the latest available release. |
141141
| `--from-branch` | Git branch that holds your current project code. Defaults to `main`. |
142142
| `--force` | Continue even if merge conflicts happen. Conflicted files are committed with conflict markers (CI/cron friendly). |
143-
| `--show-commits` | Keep full history (do not squash). **Not compatible** with `--preserve-path`. |
144-
| `--preserve-path` | Repeatable. **Squash mode only.** After copying the merge tree to the output branch, restore these paths from the base branch (e.g., `.github/workflows`). |
143+
| `--show-commits` | Keep full history (do not squash). **Not compatible** with `--restore-path`. |
144+
| `--restore-path` | Repeatable. **Squash mode only.** After copying the merge tree to the output branch, restore these paths from the base branch (e.g., `.github/workflows`). |
145145
| `--output-branch` | Name of the output branch. Default: `kubebuilder-update-from-<from-version>-to-<to-version>`. |
146146
| `--push` | Push the output branch to the `origin` remote after the update completes. |
147147
| `-h, --help` | Show help for this command. |

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ type Update struct {
5656
// unless OutputBranch is explicitly set.
5757
ShowCommits bool
5858

59-
// PreservePath is a list of paths to restore from the base branch (FromBranch)
59+
// RestorePath is a list of paths to restore from the base branch (FromBranch)
6060
// when SQUASHING, so things like CI config remain unchanged.
6161
// Example: []string{".github/workflows"}
6262
// NOTE: This is ignored when ShowCommits == true.
63-
PreservePath []string
63+
RestorePath []string
6464

6565
// OutputBranch is the name of the branch that will receive the result:
6666
// - In squash mode (ShowCommits == false): the single squashed commit.
@@ -338,9 +338,9 @@ func (opts *Update) getOutputBranchName() string {
338338
return fmt.Sprintf("kubebuilder-update-from-%s-to-%s", opts.FromVersion, opts.ToVersion)
339339
}
340340

341-
// preservePaths checks out the paths specified in PreservePath
341+
// preservePaths checks out the paths specified in RestorePath
342342
func (opts *Update) preservePaths() {
343-
for _, p := range opts.PreservePath {
343+
for _, p := range opts.RestorePath {
344344
p = strings.TrimSpace(p)
345345
if p == "" {
346346
continue
@@ -352,7 +352,7 @@ func (opts *Update) preservePaths() {
352352
}
353353

354354
// squashToOutputBranch takes the exact tree of the MergeBranch and writes it as ONE commit
355-
// on a branch derived from FromBranch (e.g., "main"). If PreservePath is set, those paths
355+
// on a branch derived from FromBranch (e.g., "main"). If RestorePath is set, those paths
356356
// are restored from the base branch after copying the merge tree, so CI config etc. stays put.
357357
func (opts *Update) squashToOutputBranch(hasConflicts bool) error {
358358
out := opts.getOutputBranchName()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ exit 0`
454454

455455
It("creates/resets output branch and commits one squashed snapshot", func() {
456456
opts.OutputBranch = "" // default naming
457-
opts.PreservePath = []string{".github/workflows"}
457+
opts.RestorePath = []string{".github/workflows"}
458458
opts.ShowCommits = false
459459

460460
err = opts.squashToOutputBranch(false) // no conflicts
@@ -499,15 +499,15 @@ if [[ "$1" == "commit" ]]; then exit 1; fi
499499
exit 0`
500500
Expect(mockBinResponse(fake, mockGit)).To(Succeed())
501501

502-
opts.PreservePath = nil
502+
opts.RestorePath = nil
503503
Expect(opts.squashToOutputBranch(false)).To(Succeed())
504504

505505
s, _ := os.ReadFile(logFile)
506506
Expect(string(s)).To(ContainSubstring("commit --no-verify -m"))
507507
})
508508

509-
It("trims preserve-path and skips blanks", func() {
510-
opts.PreservePath = []string{" .github/workflows ", "", "docs"}
509+
It("trims restore-path and skips blanks", func() {
510+
opts.RestorePath = []string{" .github/workflows ", "", "docs"}
511511
Expect(opts.squashToOutputBranch(false)).To(Succeed())
512512

513513
s, _ := os.ReadFile(logFile)

pkg/cli/alpha/update.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ The updater uses four temporary branches during the run:
4242
Output branch & history:
4343
• Default: SQUASH the merge result into ONE commit on:
4444
kubebuilder-update-from-<from-version>-to-<to-version>
45-
• --show-commits: keep full history (not compatible with --preserve-path).
45+
• --show-commits: keep full history (not compatible with --restore-path).
4646
4747
Conflicts:
4848
• Default: stop on conflicts and leave the merge branch for manual resolution.
4949
• --force: commit with conflict markers so automation can proceed.
5050
5151
Other options:
52-
• --preserve-path: restore paths from base when squashing (e.g., CI configs).
52+
• --restore-path: restore paths from base when squashing (e.g., CI configs).
5353
• --output-branch: override the output branch name.
5454
• --push: push the output branch to 'origin' after the update.
5555
@@ -70,16 +70,16 @@ Defaults:
7070
kubebuilder alpha update --from-version v4.5.0 --to-version v4.7.0 --force --show-commits
7171
7272
# Squash while preserving CI workflows from base (e.g., main)
73-
kubebuilder alpha update --force --preserve-path .github/workflows
73+
kubebuilder alpha update --force --restore-path .github/workflows
7474
7575
# Show commits into a custom output branch name
7676
kubebuilder alpha update --force --show-commits --output-branch my-update-branch
7777
7878
# Run update and push the output branch to origin (works with or without --show-commits)
7979
kubebuilder alpha update --from-version v4.6.0 --to-version v4.7.0 --force --push`,
8080
PreRunE: func(_ *cobra.Command, _ []string) error {
81-
if opts.ShowCommits && len(opts.PreservePath) > 0 {
82-
return fmt.Errorf("the --preserve-path flag is not supported with --show-commits")
81+
if opts.ShowCommits && len(opts.RestorePath) > 0 {
82+
return fmt.Errorf("the --restore-path flag is not supported with --show-commits")
8383
}
8484

8585
if err := opts.Prepare(); err != nil {
@@ -107,9 +107,9 @@ Defaults:
107107
"commit will be created automatically. Ideal for automation (e.g., cronjobs, CI).")
108108
updateCmd.Flags().BoolVar(&opts.ShowCommits, "show-commits", false,
109109
"If set, the update will keep the full history instead of squashing into a single commit.")
110-
updateCmd.Flags().StringArrayVar(&opts.PreservePath, "preserve-path", nil,
110+
updateCmd.Flags().StringArrayVar(&opts.RestorePath, "restore-path", nil,
111111
"Paths to preserve from the base branch when squashing (repeatable). Not supported with --show-commits. "+
112-
"Example: --preserve-path .github/workflows")
112+
"Example: --restore-path .github/workflows")
113113
updateCmd.Flags().StringVar(&opts.OutputBranch, "output-branch", "",
114114
"Override the default output branch name (default: kubebuilder-update-from-<from-version>-to-<to-version>).")
115115
updateCmd.Flags().BoolVar(&opts.Push, "push", false,

pkg/cli/alpha/update_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var _ = Describe("NewUpdateCommand", func() {
3636
Expect(flags.Lookup("from-branch")).NotTo(BeNil())
3737
Expect(flags.Lookup("force")).NotTo(BeNil())
3838
Expect(flags.Lookup("show-commits")).NotTo(BeNil())
39-
Expect(flags.Lookup("preserve-path")).NotTo(BeNil())
39+
Expect(flags.Lookup("restore-path")).NotTo(BeNil())
4040
Expect(flags.Lookup("output-branch")).NotTo(BeNil())
4141
Expect(flags.Lookup("push")).NotTo(BeNil())
4242
})

test/e2e/alphaupdate/update_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ var _ = Describe("kubebuilder", func() {
258258
git("add", ".github/workflows/ci.yml")
259259
git("commit", "-m", "add ci workflow")
260260

261-
By("running update (default squash) with --preserve-path")
261+
By("running update (default squash) with --restore-path")
262262
cmd := exec.Command(
263263
kbc.BinaryName, "alpha", "update",
264264
"--from-version", fromVersion,
265265
"--to-version", toVersion,
266266
"--from-branch", "main",
267-
"--preserve-path", ".github/workflows",
267+
"--restore-path", ".github/workflows",
268268
)
269269
cmd.Dir = kbc.Dir
270270
out, err := kbc.Run(cmd)

0 commit comments

Comments
 (0)