Fix linked-worktree branch checkout#9905
Fix linked-worktree branch checkout#9905kranthik10 wants to merge 4 commits intowarpdotdev:masterfrom
Conversation
Fixes warpdotdev#9170 Co-Authored-By: Warp <[email protected]>
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I reviewed this pull request and requested human review from: @warpdotdev/oss-maintainers. Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR moves the ShellGitBranch on-click value normalization into helper functions, keeps the current branch sorted first, and strips Git's * and + branch status markers before building checkout values. The added unit test covers current-branch, linked-worktree, empty, and literal-plus inputs.
Concerns
No blocking correctness or security concerns were found in the annotated diff. The targeted unit test was added, though the PR description notes the local Rust test command was blocked by the missing Apple Metal Toolchain.
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
|
Heads up: this PR strips the |
Use git worktree list --porcelain to resolve branches marked with + by git branch. Selecting one now changes into the linked worktree path instead of running a checkout that Git will reject. Co-Authored-By: Warp <[email protected]>
|
Thanks for calling this out. You were right that just stripping the marker only changes the failure mode: Git will still reject checkout when the branch is already used by another worktree. I updated this PR so the branch picker also reads I added parser coverage for the worktree path mapping and command-formatting coverage for the |
Use the standard POSIX single-quote escape so the linked-worktree fallback command remains valid when the message contains apostrophes. Co-Authored-By: Warp <[email protected]>
|
Quick update: I pushed a follow-up for the failed unit test. The test caught that the fallback message was using an extra single-quote escape, which could also make the generated shell command invalid when the message contains words like couldn't. It now uses the normal POSIX escape for single quotes. Checked locally:
The focused Rust test still does not reach the assertion on my machine because this local build is missing protoc and the Xcode Metal Toolchain, so CI is the source of truth for the full test run. |
moirahuang
left a comment
There was a problem hiding this comment.
hi @kranthik10, really appreciate you making this PR and making the updated fix so that cd-ing works!
- do you mind updating the CHANGELOG to give attribution as well to other people who attempted a fix? The relevant authors and PRs:
- in the PR description, in the testing section you say "Not applicable; this is a prompt-chip branch-name parsing fix." however, I think this has visible testing changes. mind recording a video showing the updated git chip with worktreees and switching to a worktree please?
| .map(str::to_string); | ||
| Self::linked_worktree(branch_name, worktree_path) | ||
| } | ||
| _ => Self::new(value.to_string()), |
There was a problem hiding this comment.
should we be using branch_name instead of value here?
| ); | ||
| } | ||
|
|
||
| format!("git checkout {}", branch.branch_name) |
There was a problem hiding this comment.
should we use shell_single_quote here as well?
|
|
||
| pub fn format_git_branch_command(branch_name: &str) -> String { | ||
| format!("git checkout {branch_name}") | ||
| pub fn format_git_branch_command(value: &str) -> String { |
There was a problem hiding this comment.
let's use a more descriptive name than value here to make it clear that we're expecting a GitBranchOnClickValue encoded string
| ); | ||
| } | ||
|
|
||
| #[test] |
There was a problem hiding this comment.
i know the normal git checkout case wasn't added by you but it'd be great if we can also add some tests here for the normal branch case
and also a test for decode(x.encode()) == x to guard against drift there would be great!
Quote normal branch checkout commands, clarify the encoded branch click parameter, and add tests for normal checkout formatting plus GitBranchOnClickValue encode/decode round trips. Co-Authored-By: Warp <[email protected]>
|
Question: Will we still see the |
|
@moirahuang with icon should be much better! Thanks! |
|
Updated the PR description with the demo video and the latest test results. CI is passing now too. |
I'm seeing no movement in the demo video, only a static view of a Warp window. Also mind handling this comment too please? |
@moirahuang for me the video is working fine 🤔 |
for some reason a refresh fixed it for me! |



Description
Teach the prompt branch picker to treat Git's
+branch marker as a linked-worktree action, not a checkout target.git branchmarks the current branch with*and branches checked out in another worktree with+; clicking a+branch should move the user into that worktree instead of runninggit checkout <branch>, which Git rejects.The branch list command now also fetches
git worktree list --porcelain, and Warp keeps the worktree path as hidden action data for+branches. Normal branches still rungit checkout '<branch>', quoted for shell safety. Linked-worktree branches runcd '<worktree-path>'; if the path cannot be resolved, Warp prints a clear message instead of attempting a checkout that is expected to fail.Linked Issue
Fixes #9170
ready-to-specorready-to-implement.Screenshots / Videos
Demo showing the git chip with a linked worktree branch and selecting it to move into that worktree:
Screen.Recording.2026-05-05.at.9.07.02.PM.mov
Testing
cargo fmt -- --checkgit diff --checkenv TOOLCHAINS=com.apple.dt.toolchain.Metal.32023.864 cargo test -p warp test_format_git_branch_command_checks_out_normal_branch --libenv TOOLCHAINS=com.apple.dt.toolchain.Metal.32023.864 cargo test -p warp test_git_branch_on_click_value_round_trips_through_encode_decode --lib+branches to worktree pathsGitBranchOnClickValueencode/decode round-trip coverageAgent Mode
CHANGELOG-BUG-FIX: Fixed prompt branch picker clicks for branches checked out in linked worktrees. Thanks to @JasonLovesDoggo (#9264), @tkshsbcue (#9440), and @lonexreb (#9560) for earlier fixes and investigation.
Co-Authored-By: Warp [email protected]