-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathrebase_abort.go
More file actions
74 lines (64 loc) · 1.95 KB
/
rebase_abort.go
File metadata and controls
74 lines (64 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"context"
"errors"
"fmt"
"strings"
"go.abhg.dev/gs/internal/cli"
"go.abhg.dev/gs/internal/git"
"go.abhg.dev/gs/internal/silog"
"go.abhg.dev/gs/internal/spice/state"
"go.abhg.dev/gs/internal/text"
)
type rebaseAbortCmd struct{}
func (*rebaseAbortCmd) Help() string {
name := cli.Name()
return text.Dedent(fmt.Sprintf(`
Cancels an ongoing git-spice operation that was interrupted by
a git rebase.
For example, if '%[1]s upstack restack' encounters a conflict,
cancel the operation with '%[1]s rebase abort'
(or its shorthand '%[1]s rba'),
going back to the state before the rebase.
The command can be used in place of 'git rebase --abort'
even if a git-spice operation is not currently in progress.
`, name))
}
func (cmd *rebaseAbortCmd) Run(
ctx context.Context,
wt *git.Worktree,
log *silog.Logger,
store *state.Store,
) error {
var wasRebasing bool
if _, err := wt.RebaseState(ctx); err != nil {
if !errors.Is(err, git.ErrNoRebase) {
return fmt.Errorf("get rebase state: %w", err)
}
// If the user ran 'git rebase --abort' first,
// we will not be in the middle of a rebase operation.
// That's okay, still drain the continuations
// to ensure we don't have any lingering state.
} else {
wasRebasing = true
if err := wt.RebaseAbort(ctx); err != nil {
return fmt.Errorf("abort rebase: %w", err)
}
}
conts, err := store.TakeContinuations(ctx, cli.Name()+" rebase abort")
if err != nil {
return fmt.Errorf("take rebase continuations: %w", err)
}
// Make sure that *something* happened from the user's perspective.
// If we didn't abort a rebase, and we didn't delete a continuation,
// then this was a no-op, which this command should not be.
if len(conts) == 0 && !wasRebasing {
return errors.New("no operation to abort")
}
for _, cont := range conts {
log.Debug("Rebase aborted: will not run command",
"command", strings.Join(cont.Command, " "),
"branch", cont.Branch)
}
return nil
}