package cmd import ( "context" "errors" "flag" "github.com/peterbourgon/ff/v3/ffcli" "github.com/rs/zerolog/log" ) var ( branchFS = flag.NewFlagSet("branch", flag.ContinueOnError) branchNoFetchFlag = branchFS.Bool("no-fetch", false, "Skip fetching") branchBaseFlag = branchFS.String("base", "main", "Ref to base from") Branch = &ffcli.Command{ Name: "branch", FlagSet: branchFS, ShortUsage: "branch --base [ref=main] ", ShortHelp: "branch creates a new branch called based on ", Exec: func(ctx context.Context, args []string) error { if len(args) < 1 { return errors.New("branch requires one argument") } name := args[0] base := *branchBaseFlag if base == "" { base = "upstream/main" } if !isClean() { log.Fatal().Msg("working tree is dirty") } if !*branchNoFetchFlag { fetch(ctx) } return run(ctx, "git", "checkout", "-b", name, base) }, } )