diff --git a/README.md b/README.md index 6862fd3..d3869a0 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ uv run pre-commit install - `flow create [-v]` — push the current branch and open a PR (`-v` opens it in the browser) - `flow view` — open the current branch's PR in the browser - `flow update` — update the current branch's PR title and description from the HEAD commit message +- `flow amend` — amend all changes into the HEAD commit, rebase onto the latest default branch, then + force-push - `flow merge` — auto-squash-merge the current branch's PR, then return to the default (e.g. `main`) branch - `flow rebase` — rebase the current branch onto the latest default branch diff --git a/main.go b/main.go index 5a6e0a0..4a044f1 100644 --- a/main.go +++ b/main.go @@ -30,7 +30,7 @@ func run(name string, args ...string) { func main() { if len(os.Args) < 2 { fmt.Fprintf(os.Stderr, "usage: flow [args]\n") - fmt.Fprintf(os.Stderr, "commands: branch, create, view, update, merge, clean, rebase, push, dirty\n") + fmt.Fprintf(os.Stderr, "commands: branch, create, view, update, amend, merge, clean, rebase, push, dirty\n") os.Exit(2) } @@ -43,6 +43,8 @@ func main() { cmdView(os.Args[2:]) case "update": cmdUpdate(os.Args[2:]) + case "amend": + cmdAmend(os.Args[2:]) case "merge": cmdMerge(os.Args[2:]) case "clean": @@ -55,7 +57,7 @@ func main() { cmdDirty(os.Args[2:]) default: fmt.Fprintf(os.Stderr, "flow: unknown command %q\n", os.Args[1]) - fmt.Fprintf(os.Stderr, "commands: branch, create, view, update, merge, clean, rebase, push, dirty\n") + fmt.Fprintf(os.Stderr, "commands: branch, create, view, update, amend, merge, clean, rebase, push, dirty\n") os.Exit(2) } } @@ -210,6 +212,35 @@ func cmdUpdate(args []string) { run("gh", "pr", "edit", branch, "--title", title, "--body", body) } +func cmdAmend(args []string) { + if len(args) > 0 { + fmt.Fprintf(os.Stderr, "usage: flow amend\n") + os.Exit(2) + } + + branch, err := currentBranch() + if err != nil { + fmt.Fprintf(os.Stderr, "flow: %v\n", err) + os.Exit(1) + } + + if err := assertNotDefaultBranch(branch); err != nil { + fmt.Fprintf(os.Stderr, "flow: %v\n", err) + os.Exit(1) + } + + def, err := defaultBranch() + if err != nil { + fmt.Fprintf(os.Stderr, "flow: %v\n", err) + os.Exit(1) + } + + run("git", "commit", "-a", "--amend") + run("git", "fetch", "origin", def) + run("git", "rebase", "origin/"+def) + run("git", "push", "--force") +} + func cmdMerge(args []string) { if len(args) > 0 { fmt.Fprintf(os.Stderr, "usage: flow merge\n")