From f335f5805ffd827b6dc2dbc9d4a8797413a739be Mon Sep 17 00:00:00 2001 From: jolheiser Date: Mon, 23 Jan 2023 22:41:10 -0600 Subject: [PATCH] fix: cleanup from daily usage Signed-off-by: jolheiser --- cmd/backport.go | 12 +++++++++++- cmd/cleanup.go | 6 ++++++ cmd/frontport.go | 12 +++++++++++- cmd/tag.go | 13 +++++++++++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/cmd/backport.go b/cmd/backport.go index cc462f3..6a2a28d 100644 --- a/cmd/backport.go +++ b/cmd/backport.go @@ -24,6 +24,8 @@ func (h *Handler) Backport() *ffcli.Command { fs.StringVar(toFlag, "t", *toFlag, "--to") listFlag := fs.Bool("list", false, "Open repository to see needed backports") fs.BoolVar(listFlag, "l", *listFlag, "--list") + pushFlag := fs.Bool("push", false, "Push immediately") + fs.BoolVar(pushFlag, "p", *pushFlag, "--push") return &ffcli.Command{ Name: "backport", FlagSet: fs, @@ -91,7 +93,15 @@ func (h *Handler) Backport() *ffcli.Command { return err } - return run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]) + if err := run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]); err != nil { + return err + } + + if *pushFlag { + return run(ctx, h.Config.WorkspaceBranch(branch), "git", "push", "origin", "HEAD") + } + + return nil }, } } diff --git a/cmd/cleanup.go b/cmd/cleanup.go index b1d0e2b..a29ea5a 100644 --- a/cmd/cleanup.go +++ b/cmd/cleanup.go @@ -13,6 +13,8 @@ func (h *Handler) Cleanup() *ffcli.Command { fs := flag.NewFlagSet("cleanup", flag.ContinueOnError) forceFlag := fs.Bool("force", false, "Force cleanup") fs.BoolVar(forceFlag, "f", *forceFlag, "--force") + pruneFlag := fs.Bool("prune", false, "Prune worktrees") + fs.BoolVar(pruneFlag, "p", *pruneFlag, "--prune") return &ffcli.Command{ Name: "cleanup", FlagSet: fs, @@ -23,6 +25,10 @@ func (h *Handler) Cleanup() *ffcli.Command { return err } + if *pruneFlag { + return run(ctx, h.Config.Workspace(), "git", "worktree", "prune") + } + if len(args) > 0 { for _, arg := range args { if err := removeWorktree(h, ctx, arg, *forceFlag); err != nil { diff --git a/cmd/frontport.go b/cmd/frontport.go index 8a8554a..271d839 100644 --- a/cmd/frontport.go +++ b/cmd/frontport.go @@ -18,6 +18,8 @@ func (h *Handler) Frontport() *ffcli.Command { fs.StringVar(fromFlag, "f", *fromFlag, "--from") toFlag := fs.String("to", "", "Release to frontport to (ex: `main`, default: `main`)") fs.StringVar(toFlag, "t", *toFlag, "--to") + pushFlag := fs.Bool("push", false, "Push immediately") + fs.BoolVar(pushFlag, "p", *pushFlag, "--push") return &ffcli.Command{ Name: "frontport", FlagSet: fs, @@ -83,7 +85,15 @@ func (h *Handler) Frontport() *ffcli.Command { return err } - return run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]) + if err := run(ctx, h.Config.WorkspaceBranch(branch), "git", "cherry-pick", optMap[resp]); err != nil { + return err + } + + if *pushFlag { + return run(ctx, h.Config.WorkspaceBranch(branch), "git", "push", "origin", "HEAD") + } + + return nil }, } } diff --git a/cmd/tag.go b/cmd/tag.go index 58afd7f..83d5919 100644 --- a/cmd/tag.go +++ b/cmd/tag.go @@ -23,6 +23,8 @@ var ( func (h *Handler) Tag() *ffcli.Command { fs := flag.NewFlagSet("tag", flag.ContinueOnError) + pushFlag := fs.Bool("push", false, "Push immediately") + fs.BoolVar(pushFlag, "p", *pushFlag, "--push") return &ffcli.Command{ Name: "tag", FlagSet: fs, @@ -81,7 +83,7 @@ func (h *Handler) Tag() *ffcli.Command { return err } - workspaceName := strings.ReplaceAll(branch, "/", "-") + workspaceName := fmt.Sprintf("release-%s", version) if err := h.Branch().ParseAndRun(ctx, []string{"--base", branch, workspaceName}); err != nil { return err } @@ -104,7 +106,14 @@ func (h *Handler) Tag() *ffcli.Command { if err := fi.Close(); err != nil { return err } - run(ctx, h.Config.WorkspaceBranch(workspaceName), "git", "tag", "-s", "-F", "release.notes", version) + + if err := run(ctx, h.Config.WorkspaceBranch(workspaceName), "git", "tag", "-s", "-F", "release.notes", version); err != nil { + return err + } + + if *pushFlag { + return run(ctx, h.Config.WorkspaceBranch(workspaceName), "git", "push", "upstream", version) + } fmt.Printf("cd %s && git push upstream %s \n", h.Config.WorkspaceBranch(workspaceName), version) return nil