Skip to content

Add "Create new branch" option to branch switcher#10610

Open
wzc520pyfm wants to merge 2 commits intowarpdotdev:masterfrom
wzc520pyfm:wzc520pyfm/support-create-new-branch
Open

Add "Create new branch" option to branch switcher#10610
wzc520pyfm wants to merge 2 commits intowarpdotdev:masterfrom
wzc520pyfm:wzc520pyfm/support-create-new-branch

Conversation

@wzc520pyfm
Copy link
Copy Markdown
Contributor

@wzc520pyfm wzc520pyfm commented May 10, 2026

Description

Implements the enhancement requested in #10605.

When the user types a branch name that doesn't exist in the repository, the branch switcher now shows a Create new branch "<name>" entry at the top of the results list. Selecting it runs git checkout -b <name> -- from the current HEAD, eliminating the need to leave the picker to create a new branch via the terminal — matching the experience of VS Code, GitHub Desktop, and JetBrains branch pickers.

How it works:

  • DisplayChipMenu gains an optional with_create_item_from_query hook that, when set, prepends a synthetic menu item built from the current search query whenever no existing item matches it exactly. This keeps the branch-specific logic out of the generic menu while reusing all of its selection / keyboard / click plumbing.
  • A new CreateGitBranch GenericMenuItem renders with the Plus icon and emits git checkout -b '<branch>' -- (the trailing -- guards against any flag-like input that survives front-end validation).
  • is_plausible_new_branch_name rejects empty / whitespace-only / leading-dash / whitespace-containing inputs so the affordance does not appear for clearly invalid queries; everything else is left to git itself to validate at execution time.
  • Existing branches still take precedence: if the trimmed query exactly matches an existing branch's name, only the existing branch is shown (avoiding a confusing `branch already exists` failure).

Linked Issue

Closes #10605

  • The linked issue is labeled `ready-to-spec` or `ready-to-implement`.

Note for maintainers: the issue is currently labeled `enhancement` + `triaged` but does not yet carry a `ready-to-implement` label. Happy to first land a `specs/GH10605/{product,tech}.md` PR if you'd prefer this go through the spec flow — let me know.

  • Where appropriate, screenshots or a short video of the implementation are included below.

Testing

  • Added unit tests in `display_chip_tests.rs` covering `format_create_git_branch_command` (with single-quote escaping) and `CreateGitBranch` (name formatting, action data, whitespace trimming).

  • Added unit tests in `git_branch_on_click.rs` covering `is_plausible_new_branch_name` (accepted typical names, rejected empty / whitespace-only / leading-dash / whitespace-containing inputs).

  • Ran `cargo fmt`, `cargo clippy -p warp --tests -- -D warnings`, and `cargo nextest run -p warp -E 'test(context_chips::)'` (78/78 passing, including the 9 new tests).

  • Manually tested via `./script/run`:

    1. Open branch switcher in a git repo, type a non-existent name → "Create new branch …" appears at top, default-selected.
    2. Press Enter → terminal executes `git checkout -b --`, branch chip refreshes to the new branch.
    3. Type a partial fuzzy match → create option still on top, fuzzy matches below.
    4. Type the name of an existing branch → create option disappears (no duplicate).
    5. Type `-foo` / `my branch` / whitespace → no create option (falls back to "No results found").
  • I have manually tested my changes locally with `./script/run`

Screenshots / Videos

Snipaste_create_branch_1 Snipaste_create_branch_2

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

Made with Cursor

When the user types a branch name that doesn't match any existing branch,
the branch switcher now shows a "Create new branch \"<name>\"" entry at
the top of the results. Selecting it runs `git checkout -b <name> --`
from the current HEAD, removing the friction of leaving the picker to
create a new branch via the terminal — matching the experience of
VS Code, GitHub Desktop, and JetBrains branch pickers.

Implementation:

- `DisplayChipMenu` gains an optional `with_create_item_from_query`
  hook that, when set, prepends a synthetic menu item built from the
  current search query whenever no existing item matches it exactly.
  This keeps the branch-specific logic out of the generic menu while
  reusing all of its selection / keyboard / click plumbing.
- `CreateGitBranch` is a new `GenericMenuItem` that renders with the
  Plus icon and emits `git checkout -b '<branch>' --` (the `--` guards
  against any flag-like input that survives front-end validation).
- `is_plausible_new_branch_name` rejects empty / whitespace-only /
  leading-dash / whitespace-containing inputs so the affordance does
  not appear for clearly invalid queries; everything else is left to
  git itself to validate at execution time.
- Existing branches still take precedence: if the trimmed query
  exactly matches an existing branch's name, only the existing branch
  is shown (avoiding a confusing `branch already exists` failure).

Closes warpdotdev#10605

Co-authored-by: Cursor <cursoragent@cursor.com>
@cla-bot cla-bot Bot added the cla-signed label May 10, 2026
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 10, 2026

@wzc520pyfm

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label May 10, 2026
oz-for-oss[bot]
oz-for-oss Bot previously requested changes May 10, 2026
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds a synthetic create-branch menu item to the branch switcher, formats the resulting git checkout -b command with shell quoting, and adds focused unit coverage for command formatting and basic branch-name filtering.

Concerns

  • Manual testing evidence is missing for this user-visible branch switcher change. The PR description says screenshots/videos are pending; please include screenshots or a screen recording that show creating a new branch from the picker end to end, or justify why visual evidence is not possible.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@wzc520pyfm
Copy link
Copy Markdown
Contributor Author

/oz-review I have uploaded screenshots of the manual test.

@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 10, 2026

@wzc520pyfm

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I reviewed this pull request and requested human review from: @warpdotdev/oss-maintainers.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot dismissed their stale review May 10, 2026 17:33

Oz no longer requests changes for this pull request after the latest automated review.

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds a synthetic create-branch item to the branch switcher when the search query does not exactly match an existing branch, plus command formatting, plausibility checks, and focused unit coverage.

Concerns

  • No blocking correctness or security concerns found in the reviewed diff.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot requested review from a team and captainsafia and removed request for a team May 10, 2026 17:33
Copy link
Copy Markdown
Contributor

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this PR! This looks good on first glance but I'll work with the team to get the associated issue marked as either ready-to-implement or ready-to-spec if we're ready to take a look at it.

Comment thread app/src/context_chips/display_menu.rs Outdated
if let Some(builder) = self.create_item_from_query.as_ref() {
let trimmed = self.search_query.trim();
let already_matches_existing =
self.menu_items.iter().any(|item| item.name() == trimmed);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to worry about case-sensitive matching here (Main vs main)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, the check here should ignore case, I will impl

Copy link
Copy Markdown
Contributor Author

@wzc520pyfm wzc520pyfm May 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed.

Before fix:

image

Fixed:
Snipaste_create_branch_fix_1

image

On case-insensitive filesystems (the default on macOS and Windows) git
treats refs like `main` and `Main` as the same branch, so offering a
"Create new branch \"Main\"" entry while `main` already exists just
hands the user a `branch already exists` failure from git. Make the
duplicate-detection check ASCII case-insensitive so the create
affordance is correctly suppressed for these case-only variants.

The duplicate-check predicate is extracted into a small free helper
`query_matches_existing_name` so the case-insensitive contract can be
exercised directly in unit tests without standing up a full
`DisplayChipMenu`.

Co-authored-by: Cursor <cursoragent@cursor.com>
@wzc520pyfm wzc520pyfm requested a review from captainsafia May 11, 2026 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Branch switcher should allow creating a new branch when typed name does not exist

2 participants