Fix linked-worktree branch checkout#9905
Conversation
|
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 |
|
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 |
|
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
| @@ -40,6 +42,36 @@ fn test_github_pr_chip_display_value_falls_back_to_raw_value() { | |||
| ); | |||
| } | |||
|
|
|||
| #[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!
|
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! |
|
@kranthik10 I'm going to loop in oz-agent to make the icon change so we can try to land this PR soon! @oz-agent please update the git branch icon in the git chip to be the worktree icon if the branch is tied to a worktree |
|
I ran into an unexpected error while working on this. Powered by Oz |
|
@oz-agent please update the git branch icon in the git chip to be the worktree icon if the branch is tied to a worktree |
|
I'm working on changes requested in this PR (responding to a PR conversation comment). You can view the conversation on Warp. I pushed changes to this PR based on the comment. Next steps:
Powered by Oz |
Fixes warpdotdev#9170 Co-Authored-By: Warp <agent@warp.dev>
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 <agent@warp.dev>
Use the standard POSIX single-quote escape so the linked-worktree fallback command remains valid when the message contains apostrophes. Co-Authored-By: Warp <agent@warp.dev>
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 <agent@warp.dev>
Co-Authored-By: Moira Huang <moirahuang@users.noreply.github.com>
e4efece to
0899903
Compare
|
/oz-review |
|
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 |
There was a problem hiding this comment.
Overview
This PR updates the git branch prompt chip to distinguish linked-worktree branches from checkout targets, carries linked worktree paths through hidden menu action data, and formats click commands so normal branches are checked out while linked-worktree branches change directories.
Concerns
No blocking correctness or security concerns found in the annotated 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
moirahuang
left a comment
There was a problem hiding this comment.
@kranthik10 thanks for your work on this PR!
## Description Teach the prompt branch picker to treat Git's `+` branch marker as a linked-worktree action, not a checkout target. `git branch` marks the current branch with `*` and branches checked out in another worktree with `+`; clicking a `+` branch should move the user into that worktree instead of running `git 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 run `git checkout '<branch>'`, quoted for shell safety. Linked-worktree branches run `cd '<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 warpdotdev#9170 - [x] The linked issue is labeled `ready-to-spec` or `ready-to-implement`. - [x] Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes). ## Screenshots / Videos Demo showing the git chip with a linked worktree branch and selecting it to move into that worktree: https://github.com/user-attachments/assets/5b31d204-9e13-4855-8977-cbd5bc0ad1bd ## Testing - `cargo fmt -- --check` - `git diff --check` - `env TOOLCHAINS=com.apple.dt.toolchain.Metal.32023.864 cargo test -p warp test_format_git_branch_command_checks_out_normal_branch --lib` - `env TOOLCHAINS=com.apple.dt.toolchain.Metal.32023.864 cargo test -p warp test_git_branch_on_click_value_round_trips_through_encode_decode --lib` - Added parser coverage for resolving `+` branches to worktree paths - Added `GitBranchOnClickValue` encode/decode round-trip coverage - Added command formatting coverage for normal branch checkout quoting, linked-worktree branch clicks, and the missing-path fallback - GitHub CI is passing ## Agent Mode - [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode CHANGELOG-BUG-FIX: Fixed prompt branch picker clicks for branches checked out in linked worktrees. Thanks to @JasonLovesDoggo (warpdotdev#9264), @tkshsbcue (warpdotdev#9440), and @lonexreb (warpdotdev#9560) for earlier fixes and investigation. Co-Authored-By: Warp <agent@warp.dev> --------- Co-authored-by: Warp <agent@warp.dev> Co-authored-by: Oz <oz-agent@warp.dev> Co-authored-by: Moira Huang <moirahuang@users.noreply.github.com>
## Description Teach the prompt branch picker to treat Git's `+` branch marker as a linked-worktree action, not a checkout target. `git branch` marks the current branch with `*` and branches checked out in another worktree with `+`; clicking a `+` branch should move the user into that worktree instead of running `git 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 run `git checkout '<branch>'`, quoted for shell safety. Linked-worktree branches run `cd '<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 warpdotdev#9170 - [x] The linked issue is labeled `ready-to-spec` or `ready-to-implement`. - [x] Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes). ## Screenshots / Videos Demo showing the git chip with a linked worktree branch and selecting it to move into that worktree: https://github.com/user-attachments/assets/5b31d204-9e13-4855-8977-cbd5bc0ad1bd ## Testing - `cargo fmt -- --check` - `git diff --check` - `env TOOLCHAINS=com.apple.dt.toolchain.Metal.32023.864 cargo test -p warp test_format_git_branch_command_checks_out_normal_branch --lib` - `env TOOLCHAINS=com.apple.dt.toolchain.Metal.32023.864 cargo test -p warp test_git_branch_on_click_value_round_trips_through_encode_decode --lib` - Added parser coverage for resolving `+` branches to worktree paths - Added `GitBranchOnClickValue` encode/decode round-trip coverage - Added command formatting coverage for normal branch checkout quoting, linked-worktree branch clicks, and the missing-path fallback - GitHub CI is passing ## Agent Mode - [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode CHANGELOG-BUG-FIX: Fixed prompt branch picker clicks for branches checked out in linked worktrees. Thanks to @JasonLovesDoggo (warpdotdev#9264), @tkshsbcue (warpdotdev#9440), and @lonexreb (warpdotdev#9560) for earlier fixes and investigation. Co-Authored-By: Warp <agent@warp.dev> --------- Co-authored-by: Warp <agent@warp.dev> Co-authored-by: Oz <oz-agent@warp.dev> Co-authored-by: Moira Huang <moirahuang@users.noreply.github.com> (cherry picked from commit 59e802e)
## Description Teach the prompt branch picker to treat Git's `+` branch marker as a linked-worktree action, not a checkout target. `git branch` marks the current branch with `*` and branches checked out in another worktree with `+`; clicking a `+` branch should move the user into that worktree instead of running `git 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 run `git checkout '<branch>'`, quoted for shell safety. Linked-worktree branches run `cd '<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 warpdotdev#9170 - [x] The linked issue is labeled `ready-to-spec` or `ready-to-implement`. - [x] Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes). ## Screenshots / Videos Demo showing the git chip with a linked worktree branch and selecting it to move into that worktree: https://github.com/user-attachments/assets/5b31d204-9e13-4855-8977-cbd5bc0ad1bd ## Testing - `cargo fmt -- --check` - `git diff --check` - `env TOOLCHAINS=com.apple.dt.toolchain.Metal.32023.864 cargo test -p warp test_format_git_branch_command_checks_out_normal_branch --lib` - `env TOOLCHAINS=com.apple.dt.toolchain.Metal.32023.864 cargo test -p warp test_git_branch_on_click_value_round_trips_through_encode_decode --lib` - Added parser coverage for resolving `+` branches to worktree paths - Added `GitBranchOnClickValue` encode/decode round-trip coverage - Added command formatting coverage for normal branch checkout quoting, linked-worktree branch clicks, and the missing-path fallback - GitHub CI is passing ## Agent Mode - [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode CHANGELOG-BUG-FIX: Fixed prompt branch picker clicks for branches checked out in linked worktrees. Thanks to @JasonLovesDoggo (warpdotdev#9264), @tkshsbcue (warpdotdev#9440), and @lonexreb (warpdotdev#9560) for earlier fixes and investigation. Co-Authored-By: Warp <agent@warp.dev> --------- Co-authored-by: Warp <agent@warp.dev> Co-authored-by: Oz <oz-agent@warp.dev> Co-authored-by: Moira Huang <moirahuang@users.noreply.github.com>




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 agent@warp.dev