-
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathdownstack_track.go
More file actions
45 lines (37 loc) · 1.01 KB
/
downstack_track.go
File metadata and controls
45 lines (37 loc) · 1.01 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
package main
import (
"context"
"fmt"
"go.abhg.dev/gs/internal/git"
"go.abhg.dev/gs/internal/handler/track"
"go.abhg.dev/gs/internal/text"
)
type downstackTrackCmd struct {
Branch string `arg:"" optional:"" help:"Name of the branch to start tracking from" predictor:"branches"`
}
func (*downstackTrackCmd) Help() string {
return text.Dedent(`
Track all untracked branches in the downstack of a branch.
Starting from the specified branch (or current branch),
identify and track any untracked branches downstack from it,
until reaching trunk or an already-tracked branch.
`)
}
func (cmd *downstackTrackCmd) AfterApply(
ctx context.Context,
wt *git.Worktree,
) error {
if cmd.Branch == "" {
var err error
cmd.Branch, err = wt.CurrentBranch(ctx)
if err != nil {
return fmt.Errorf("get current branch: %w", err)
}
}
return nil
}
func (cmd *downstackTrackCmd) Run(ctx context.Context, handler TrackHandler) error {
return handler.TrackDownstack(ctx, &track.DownstackRequest{
Branch: cmd.Branch,
})
}