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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
4 changes: 2 additions & 2 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion cmd/wt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions cmd/wt/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions internal/ui/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Loading