forked from abhinav/git-spice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbranch_untrack.go
51 lines (41 loc) · 1.16 KB
/
branch_untrack.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
package main
import (
"context"
"errors"
"fmt"
"github.com/charmbracelet/log"
"go.abhg.dev/gs/internal/spice/state"
"go.abhg.dev/gs/internal/text"
)
type branchUntrackCmd struct {
Branch string `arg:"" optional:"" help:"Name of the branch to untrack. Defaults to current." predictor:"branches"`
}
func (*branchUntrackCmd) Help() string {
return text.Dedent(`
The current branch is deleted from git-spice's data store
but not deleted from the repository.
Branches upstack from it are not affected,
and will use the next branch downstack as their new base.
Provide a branch name as an argument to target
a different branch.
`)
}
func (cmd *branchUntrackCmd) Run(ctx context.Context, log *log.Logger, opts *globalOptions) error {
repo, _, svc, err := openRepo(ctx, log, opts)
if err != nil {
return err
}
if cmd.Branch == "" {
cmd.Branch, err = repo.CurrentBranch(ctx)
if err != nil {
return fmt.Errorf("get current branch: %w", err)
}
}
if err := svc.ForgetBranch(ctx, cmd.Branch); err != nil {
if errors.Is(err, state.ErrNotExist) {
return errors.New("branch not tracked")
}
return fmt.Errorf("forget branch: %w", err)
}
return nil
}