Skip to content

Fix linked-worktree branch checkout#9905

Open
kranthik10 wants to merge 4 commits intowarpdotdev:masterfrom
kranthik10:codex/fix-linked-worktree-branch-picker
Open

Fix linked-worktree branch checkout#9905
kranthik10 wants to merge 4 commits intowarpdotdev:masterfrom
kranthik10:codex/fix-linked-worktree-branch-picker

Conversation

@kranthik10
Copy link
Copy Markdown
Contributor

@kranthik10 kranthik10 commented May 2, 2026

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 #9170

  • The linked issue is labeled ready-to-spec or ready-to-implement.
  • 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:

Screen.Recording.2026-05-05.at.9.07.02.PM.mov

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

  • 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 (#9264), @tkshsbcue (#9440), and @lonexreb (#9560) for earlier fixes and investigation.

Co-Authored-By: Warp [email protected]

@cla-bot cla-bot Bot added the cla-signed label May 2, 2026
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label May 2, 2026
@kranthik10 kranthik10 marked this pull request as ready for review May 2, 2026 13:28
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 2, 2026

@kranthik10

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 /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

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 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

@oz-for-oss oz-for-oss Bot requested review from a team and lucieleblanc and removed request for a team May 2, 2026 13:33
@unrevised6419
Copy link
Copy Markdown

Heads up: this PR strips the + marker but the underlying checkout will still fail because the branch is already used by a linked worktree (fatal: '<branch>' is already checked out at ...). See #9170 (comment) for details and suggested fixes.

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]>
@kranthik10
Copy link
Copy Markdown
Contributor Author

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 git worktree list --porcelain. For + branches, Warp now keeps the linked worktree path as action data and emits cd '<path>' when that item is selected. Normal branches still use git checkout <branch>. If Git marks a branch with + but we can’t resolve the path, Warp now prints a clear message instead of attempting a checkout that should fail.

I added parser coverage for the worktree path mapping and command-formatting coverage for the cd behavior/fallback. Local cargo test is still blocked on my machine by the missing Apple Metal Toolchain, but cargo fmt -- --check and git diff --check pass.

@moirahuang moirahuang requested review from moirahuang and removed request for lucieleblanc May 5, 2026 18:10
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]>
@kranthik10
Copy link
Copy Markdown
Contributor Author

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:

  • cargo fmt -- --check
  • git diff --check
  • a small zsh smoke test for the generated command

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.

Copy link
Copy Markdown
Contributor

@moirahuang moirahuang left a comment

Choose a reason for hiding this comment

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

hi @kranthik10, really appreciate you making this PR and making the updated fix so that cd-ing works!

  1. do you mind updating the CHANGELOG to give attribution as well to other people who attempted a fix? The relevant authors and PRs:
  1. 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()),
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.

should we be using branch_name instead of value here?

Comment thread app/src/context_chips/display_chip.rs Outdated
);
}

format!("git checkout {}", branch.branch_name)
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.

should we use shell_single_quote here as well?

Comment thread app/src/context_chips/display_chip.rs Outdated

pub fn format_git_branch_command(branch_name: &str) -> String {
format!("git checkout {branch_name}")
pub fn format_git_branch_command(value: &str) -> String {
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.

let's use a more descriptive name than value here to make it clear that we're expecting a GitBranchOnClickValue encoded string

);
}

#[test]
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.

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]>
@unrevised6419
Copy link
Copy Markdown

Question: Will we still see the + <branch-name> in the dropdown? I would expect the + to remain, so we know that is a workspace.

@moirahuang
Copy link
Copy Markdown
Contributor

moirahuang commented May 5, 2026

Question: Will we still see the + <branch-name> in the dropdown? I would expect the + to remain, so we know that is a workspace.

My proposed behavior here is that we should strip + from the dropdown (I think that reads better) but swap out the icon for branch (first screenshot) to be the worktree icon (second screenshot) instead. This will have your intended effect of knowing what are worktrees vs. regular git branches, while visually looking better

Screenshot 2026-05-05 at 12 29 00 PM Screenshot 2026-05-05 at 12 29 06 PM

@unrevised6419
Copy link
Copy Markdown

unrevised6419 commented May 5, 2026

@moirahuang with icon should be much better! Thanks!

@kranthik10
Copy link
Copy Markdown
Contributor Author

Updated the PR description with the demo video and the latest test results. CI is passing now too.

@kranthik10 kranthik10 requested a review from moirahuang May 5, 2026 20:23
@moirahuang
Copy link
Copy Markdown
Contributor

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?
Screenshot 2026-05-05 at 1 49 55 PM

@unrevised6419
Copy link
Copy Markdown

I'm seeing no movement in the demo video

@moirahuang for me the video is working fine 🤔

@moirahuang
Copy link
Copy Markdown
Contributor

I'm seeing no movement in the demo video

@moirahuang for me the video is working fine 🤔

for some reason a refresh fixed it for me!

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 picker includes linked-worktree '+' marker in git checkout

3 participants