39 lines
851 B
Go
39 lines
851 B
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"flag"
|
|
|
|
"github.com/peterbourgon/ff/v3/ffcli"
|
|
)
|
|
|
|
var (
|
|
branchFS = flag.NewFlagSet("branch", flag.ContinueOnError)
|
|
branchNoFetch = branchFS.Bool("no-fetch", false, "Skip fetching")
|
|
Branch = &ffcli.Command{
|
|
Name: "branch",
|
|
FlagSet: branchFS,
|
|
ShortUsage: "branch <name> [base=main]",
|
|
ShortHelp: "branch creates a new branch called <name> based on [base]",
|
|
Exec: func(ctx context.Context, args []string) error {
|
|
if len(args) < 1 {
|
|
return errors.New("branch requires at least one argument")
|
|
}
|
|
|
|
name, base := args[0], "upstream/main"
|
|
if len(args) > 1 {
|
|
base = args[1]
|
|
}
|
|
|
|
if !*branchNoFetch {
|
|
if err := run(ctx, "git", "fetch", "upstream"); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return run(ctx, "git", "checkout", "-b", name, base)
|
|
},
|
|
}
|
|
)
|