Add "Create new branch" option to branch switcher#10610
Add "Create new branch" option to branch switcher#10610wzc520pyfm wants to merge 2 commits intowarpdotdev:masterfrom
Conversation
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>
|
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 Powered by Oz |
There was a problem hiding this comment.
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
|
/oz-review I have uploaded screenshots of the manual test. |
|
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: Comment Powered by Oz |
Oz no longer requests changes for this pull request after the latest automated review.
There was a problem hiding this comment.
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
captainsafia
left a comment
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
Do we need to worry about case-sensitive matching here (Main vs main)?
There was a problem hiding this comment.
You are right, the check here should ignore case, I will impl
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>



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 runsgit 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:
DisplayChipMenugains an optionalwith_create_item_from_queryhook 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.CreateGitBranchGenericMenuItemrenders with the Plus icon and emitsgit checkout -b '<branch>' --(the trailing--guards against any flag-like input that survives front-end validation).is_plausible_new_branch_namerejects 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.Linked Issue
Closes #10605
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`:
I have manually tested my changes locally with `./script/run`
Screenshots / Videos
Agent Mode
Made with Cursor