Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 33 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func run(name string, args ...string) {
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "usage: flow <command> [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)
}

Expand All @@ -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":
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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")
Expand Down
Loading