diff --git a/README.md b/README.md index 18af049..4090a45 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Select branch or worktree (j/k, / to filter, c to mark, ? for help) repository. ```bash -wt pr # list open PRs with number, title and branch; pick one to switch to +wt pr # list open PRs with number, branch and title; pick one to switch to wt pr 123 # switch straight to the branch of PR #123 ``` diff --git a/SPEC.md b/SPEC.md index 1a8c4d1..6f4c964 100644 --- a/SPEC.md +++ b/SPEC.md @@ -155,7 +155,7 @@ or clearing marks. The hint line and `?` overlay document the binding. ``` wt # interactive picker, default action -wt pr # list open PRs (#number, title, branch) and pick one +wt pr # list open PRs (#number, branch, title) and pick one wt pr 123 # switch to the branch of PR #123 wt --path-only # print a selected worktree path for shell integration wt --worktree-root DIR # base dir for new worktrees (overrides config) @@ -164,7 +164,7 @@ wt --version / --help ``` **Pull requests:** `wt pr` runs `gh pr list --state open --json -number,title,headRefName` and shows a picker with `#number title (branch)` +number,title,headRefName` and shows a picker with `#number branch title` rows; `wt pr 123` runs `gh pr view 123 --json ...` and skips the picker. Both then call `action.PreparePRBranch(branch, worktreePath, confirm)`: fetch that branch from `origin`, create the local branch if missing, or — if the local diff --git a/cmd/wt/main.go b/cmd/wt/main.go index da0a2ae..2bbf52d 100644 --- a/cmd/wt/main.go +++ b/cmd/wt/main.go @@ -198,7 +198,7 @@ func runPR(number string, pathOnly bool, worktreeRootFlag string, noColor bool) for _, pr := range prs { items = append(items, gitdata.Item{ Branch: pr.Branch, - Display: fmt.Sprintf("#%d %s (%s)", pr.Number, pr.Title, pr.Branch), + Display: prDisplay(pr), }) } top, err := gitdata.Toplevel() @@ -254,6 +254,10 @@ func runPR(number string, pathOnly bool, worktreeRootFlag string, noColor bool) return nil } +func prDisplay(pr github.PR) string { + return fmt.Sprintf("#%d %s %s", pr.Number, pr.Branch, pr.Title) +} + // itemForBranch returns the picker item for branch, or a bare item when the // branch does not exist locally yet. func itemForBranch(branch string) (gitdata.Item, error) { diff --git a/cmd/wt/main_test.go b/cmd/wt/main_test.go index f98799a..59fe68e 100644 --- a/cmd/wt/main_test.go +++ b/cmd/wt/main_test.go @@ -4,8 +4,17 @@ import ( "bufio" "os" "testing" + + "github.com/AgileIndustrialComplex/wt/internal/github" ) +func TestPRDisplayOrder(t *testing.T) { + got := prDisplay(github.PR{Number: 17, Branch: "feature/x", Title: "Add F key"}) + if want := "#17 feature/x Add F key"; got != want { + t.Fatalf("prDisplay() = %q, want %q", got, want) + } +} + func TestSubcommandSkipsLeadingWrapperFlags(t *testing.T) { for _, tc := range []struct { args []string diff --git a/internal/ui/ui.go b/internal/ui/ui.go index ccb8790..708cd3a 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -78,7 +78,7 @@ func New(items []gitdata.Item, toplevel string, worktreeRoot string, noColor boo } // NewPR builds a picker for PR branches. Rows are labelled with the PR -// number and title, and the mark/delete/force-update keys are disabled. +// number, branch and title, and the mark/delete/force-update keys are disabled. func NewPR(items []gitdata.Item, toplevel string, worktreeRoot string, noColor bool, defaultAction, keymap string) Model { m := NewConfigured(items, toplevel, worktreeRoot, noColor, defaultAction, keymap) m.prMode = true @@ -513,7 +513,7 @@ func (m Model) proposeWorktreePath(branch string) string { } // itemLabel is the text shown in the picker. PR rows carry a label with the -// PR number and title; ordinary rows show their branch name. +// PR number, branch and title; ordinary rows show their branch name. func itemLabel(item gitdata.Item) string { if item.Display != "" { return item.Display diff --git a/internal/ui/ui_test.go b/internal/ui/ui_test.go index 17bcee2..6064dce 100644 --- a/internal/ui/ui_test.go +++ b/internal/ui/ui_test.go @@ -706,19 +706,17 @@ func TestSelectedStyleResumesAfterNestedStyleReset(t *testing.T) { func prItems() []gitdata.Item { return []gitdata.Item{ - {Branch: "feature/force-update", Display: "#17 Add F key (feature/force-update)"}, - {Branch: "feature/pr", Display: "#18 PR support (feature/pr)"}, + {Branch: "feature/force-update", Display: "#17 feature/force-update Add F key"}, + {Branch: "feature/pr", Display: "#18 feature/pr PR support"}, } } func TestPRPickerShowsNumberAndTitle(t *testing.T) { m := NewPR(prItems(), "/repo/proj", "", true, config.ActionPrompt, config.KeymapVim) view := m.View() - if !strings.Contains(view, "#17 Add F key") || !strings.Contains(view, "#18 PR support") { - t.Fatalf("PR picker view missing labels:\n%s", view) - } - if !strings.Contains(view, "feature/force-update") { - t.Fatalf("PR picker view missing branch name:\n%s", view) + if !strings.Contains(view, "#17 feature/force-update Add F key") || + !strings.Contains(view, "#18 feature/pr PR support") { + t.Fatalf("PR picker view missing labels in number/branch/title order:\n%s", view) } }