-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbottom.go
54 lines (46 loc) · 1.12 KB
/
bottom.go
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
package main
import (
"context"
"errors"
"fmt"
"github.com/charmbracelet/log"
"go.abhg.dev/gs/internal/git"
"go.abhg.dev/gs/internal/spice"
"go.abhg.dev/gs/internal/spice/state"
"go.abhg.dev/gs/internal/text"
"go.abhg.dev/gs/internal/ui"
)
type bottomCmd struct {
checkoutOptions
}
func (*bottomCmd) Help() string {
return text.Dedent(`
Checks out the bottom-most branch in the current branch's stack.
Use the -n flag to print the branch without checking it out.
`)
}
func (cmd *bottomCmd) Run(
ctx context.Context,
log *log.Logger,
view ui.View,
repo *git.Repository,
store *state.Store,
svc *spice.Service,
) error {
current, err := repo.CurrentBranch(ctx)
if err != nil {
// TODO: handle not a branch
return fmt.Errorf("get current branch: %w", err)
}
if current == store.Trunk() {
return errors.New("no branches below current: already on trunk")
}
bottom, err := svc.FindBottom(ctx, current)
if err != nil {
return fmt.Errorf("find bottom: %w", err)
}
return (&branchCheckoutCmd{
checkoutOptions: cmd.checkoutOptions,
Branch: bottom,
}).Run(ctx, log, view, repo, store, svc)
}