Skip to content

Commit 8734bf6

Browse files
MrFlounderclaude
andcommitted
fix(wip): use target workspace branch when restoring cross-workspace
When restoring a WIP to a different workspace than it was saved from, use that workspace's own branch instead of the original saved branch. Prevents "branch already exists" errors on cross-workspace restore. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c1eb24f commit 8734bf6

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/crabcode

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,11 +2818,16 @@ _restore_wip() {
28182818

28192819
cd "$dir"
28202820

2821-
# Switch to saved branch
2821+
# Use workspace's own branch when restoring cross-workspace, otherwise
2822+
# use the saved branch so we land on the exact same branch as before.
28222823
local current_branch=$(git branch --show-current)
2823-
if [ "$current_branch" != "$saved_branch" ] && [ -n "$saved_branch" ]; then
2824-
echo " Switching to branch $saved_branch..."
2825-
git checkout "$saved_branch" 2>/dev/null || git checkout -b "$saved_branch"
2824+
local target_branch="$saved_branch"
2825+
if [ "$saved_branch" != "$branch_name" ]; then
2826+
target_branch="$branch_name"
2827+
fi
2828+
if [ "$current_branch" != "$target_branch" ] && [ -n "$target_branch" ]; then
2829+
echo " Switching to branch $target_branch..."
2830+
git checkout "$target_branch" 2>/dev/null || git checkout -b "$target_branch"
28262831
fi
28272832

28282833
# Cherry-pick saved commits (handle both main-commits.txt and cloud-commits.txt)

0 commit comments

Comments
 (0)