Skip to content

Commit 157d87c

Browse files
committed
rename update to rebase
1 parent 86d342e commit 157d87c

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

cmd/update.go renamed to cmd/rebase.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/spf13/cobra"
1313
)
1414

15-
type updateOptions struct {
15+
type rebaseOptions struct {
1616
branch string
1717
downstack bool
1818
upstack bool
@@ -30,50 +30,50 @@ type rebaseState struct {
3030

3131
const rebaseStateFile = "gh-stack-rebase-state"
3232

33-
func UpdateCmd(cfg *config.Config) *cobra.Command {
34-
opts := &updateOptions{}
33+
func RebaseCmd(cfg *config.Config) *cobra.Command {
34+
opts := &rebaseOptions{}
3535

3636
cmd := &cobra.Command{
37-
Use: "update [branch]",
38-
Short: "Update and rebase a stack of branches",
37+
Use: "rebase [branch]",
38+
Short: "Rebase a stack of branches",
3939
Long: `Pull from remote and do a cascading rebase across the stack.
4040
4141
Ensures that each branch in the stack has the tip of the previous
4242
layer in its commit history, rebasing if necessary.`,
43-
Example: ` $ gh stack update
44-
$ gh stack update --downstack
45-
$ gh stack update --continue
46-
$ gh stack update --abort`,
43+
Example: ` $ gh stack rebase
44+
$ gh stack rebase --downstack
45+
$ gh stack rebase --continue
46+
$ gh stack rebase --abort`,
4747
Args: cobra.MaximumNArgs(1),
4848
RunE: func(cmd *cobra.Command, args []string) error {
4949
if len(args) > 0 {
5050
opts.branch = args[0]
5151
}
52-
return runUpdate(cfg, opts)
52+
return runRebase(cfg, opts)
5353
},
5454
}
5555

56-
cmd.Flags().BoolVar(&opts.downstack, "downstack", false, "Only update branches from trunk to current branch")
57-
cmd.Flags().BoolVar(&opts.upstack, "upstack", false, "Only update branches from current branch to top")
56+
cmd.Flags().BoolVar(&opts.downstack, "downstack", false, "Only rebase branches from trunk to current branch")
57+
cmd.Flags().BoolVar(&opts.upstack, "upstack", false, "Only rebase branches from current branch to top")
5858
cmd.Flags().BoolVar(&opts.cont, "continue", false, "Continue rebase after resolving conflicts")
5959
cmd.Flags().BoolVar(&opts.abort, "abort", false, "Abort rebase and restore all branches")
6060

6161
return cmd
6262
}
6363

64-
func runUpdate(cfg *config.Config, opts *updateOptions) error {
64+
func runRebase(cfg *config.Config, opts *rebaseOptions) error {
6565
gitDir, err := git.GitDir()
6666
if err != nil {
6767
cfg.Errorf("not a git repository")
6868
return nil
6969
}
7070

7171
if opts.cont {
72-
return continueUpdate(cfg, gitDir)
72+
return continueRebase(cfg, gitDir)
7373
}
7474

7575
if opts.abort {
76-
return abortUpdate(cfg, gitDir)
76+
return abortRebase(cfg, gitDir)
7777
}
7878

7979
sf, err := stack.Load(gitDir)
@@ -125,23 +125,23 @@ func runUpdate(cfg *config.Config, opts *updateOptions) error {
125125
startIdx = currentIdx
126126
}
127127

128-
branchesToUpdate := s.Branches[startIdx:endIdx]
128+
branchesToRebase := s.Branches[startIdx:endIdx]
129129

130-
if len(branchesToUpdate) == 0 {
131-
cfg.Printf("No branches to update")
130+
if len(branchesToRebase) == 0 {
131+
cfg.Printf("No branches to rebase")
132132
return nil
133133
}
134134

135-
cfg.Printf("Updating branches in order, starting from %s to %s",
136-
branchesToUpdate[0].Branch, branchesToUpdate[len(branchesToUpdate)-1].Branch)
135+
cfg.Printf("Rebasing branches in order, starting from %s to %s",
136+
branchesToRebase[0].Branch, branchesToRebase[len(branchesToRebase)-1].Branch)
137137

138138
originalRefs := make(map[string]string)
139139
for _, b := range s.Branches {
140140
sha, _ := git.HeadSHA(b.Branch)
141141
originalRefs[b.Branch] = sha
142142
}
143143

144-
for i, br := range branchesToUpdate {
144+
for i, br := range branchesToRebase {
145145
var base string
146146
absIdx := startIdx + i
147147
if absIdx == 0 {
@@ -160,8 +160,8 @@ func runUpdate(cfg *config.Config, opts *updateOptions) error {
160160
cfg.Warningf("Rebasing %s onto %s ... conflict", br.Branch, base)
161161

162162
remaining := make([]string, 0)
163-
for j := i + 1; j < len(branchesToUpdate); j++ {
164-
remaining = append(remaining, branchesToUpdate[j].Branch)
163+
for j := i + 1; j < len(branchesToRebase); j++ {
164+
remaining = append(remaining, branchesToRebase[j].Branch)
165165
}
166166

167167
state := &rebaseState{
@@ -177,9 +177,9 @@ func runUpdate(cfg *config.Config, opts *updateOptions) error {
177177
cfg.Printf("")
178178

179179
cfg.Printf("Resolve conflicts on %s, then run %s",
180-
br.Branch, cfg.ColorCyan("gh stack update --continue"))
180+
br.Branch, cfg.ColorCyan("gh stack rebase --continue"))
181181
cfg.Printf("Or abort this operation with %s",
182-
cfg.ColorCyan("gh stack update --abort"))
182+
cfg.ColorCyan("gh stack rebase --abort"))
183183
return fmt.Errorf("rebase conflict on %s", br.Branch)
184184
}
185185

@@ -201,14 +201,14 @@ func runUpdate(cfg *config.Config, opts *updateOptions) error {
201201
rangeDesc = fmt.Sprintf("All upstack branches from %s", currentBranch)
202202
}
203203

204-
cfg.Printf("%s updated locally with %s", rangeDesc, s.Trunk.Branch)
204+
cfg.Printf("%s rebased locally with %s", rangeDesc, s.Trunk.Branch)
205205
cfg.Printf("To push up your changes and open/update the stack of PRs, run %s",
206206
cfg.ColorCyan("gh stack push -f"))
207207

208208
return nil
209209
}
210210

211-
func continueUpdate(cfg *config.Config, gitDir string) error {
211+
func continueRebase(cfg *config.Config, gitDir string) error {
212212
state, err := loadRebaseState(gitDir)
213213
if err != nil {
214214
cfg.Errorf("no rebase in progress")
@@ -235,7 +235,7 @@ func continueUpdate(cfg *config.Config, gitDir string) error {
235235
conflictBranch = s.Branches[state.CurrentBranchIndex].Branch
236236
}
237237

238-
cfg.Printf("Continuing update of stack, resuming from %s to %s",
238+
cfg.Printf("Continuing rebase of stack, resuming from %s to %s",
239239
conflictBranch, s.Branches[len(s.Branches)-1].Branch)
240240

241241
if git.IsRebaseInProgress() {
@@ -285,9 +285,9 @@ func continueUpdate(cfg *config.Config, gitDir string) error {
285285
printConflictDetails(cfg, base)
286286
cfg.Printf("")
287287
cfg.Printf("Resolve conflicts on %s, then run %s",
288-
branchName, cfg.ColorCyan("gh stack update --continue"))
288+
branchName, cfg.ColorCyan("gh stack rebase --continue"))
289289
cfg.Printf("Or abort this operation with %s",
290-
cfg.ColorCyan("gh stack update --abort"))
290+
cfg.ColorCyan("gh stack rebase --abort"))
291291
return fmt.Errorf("rebase conflict on %s", branchName)
292292
}
293293

@@ -303,14 +303,14 @@ func continueUpdate(cfg *config.Config, gitDir string) error {
303303
}
304304
_ = stack.Save(gitDir, sf)
305305

306-
cfg.Printf("All branches in stack updated locally with %s", s.Trunk.Branch)
306+
cfg.Printf("All branches in stack rebased locally with %s", s.Trunk.Branch)
307307
cfg.Printf("To push up your changes and open/update the stack of PRs, run %s",
308308
cfg.ColorCyan("gh stack push -f"))
309309

310310
return nil
311311
}
312312

313-
func abortUpdate(cfg *config.Config, gitDir string) error {
313+
func abortRebase(cfg *config.Config, gitDir string) error {
314314
state, err := loadRebaseState(gitDir)
315315
if err != nil {
316316
cfg.Errorf("no rebase in progress")
@@ -382,5 +382,5 @@ func printConflictDetails(cfg *config.Config, branch string) {
382382
cfg.Printf(" %s (changes being rebased)", cfg.ColorCyan(">>>>>>>"))
383383
cfg.Printf(" 2. Edit the file to keep the desired changes and remove the markers")
384384
cfg.Printf(" 3. Stage resolved files: %s", cfg.ColorCyan("git add <file>"))
385-
cfg.Printf(" 4. Continue the update: %s", cfg.ColorCyan("gh stack update --continue"))
385+
cfg.Printf(" 4. Continue the rebase: %s", cfg.ColorCyan("gh stack rebase --continue"))
386386
}

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func RootCmd() *cobra.Command {
3333

3434
// Helper commands
3535
root.AddCommand(ViewCmd(cfg))
36-
root.AddCommand(UpdateCmd(cfg))
36+
root.AddCommand(RebaseCmd(cfg))
3737

3838
// Navigation commands
3939
root.AddCommand(UpCmd(cfg))

0 commit comments

Comments
 (0)