Skip to content

Commit 72bab73

Browse files
author
Dag Jomar Mersland
committed
[Cursor] Fix: git stack create now properly renames branch instead of creating duplicate
Problem: When converting an existing branch to a stack branch using 'git stack create', the original branch was left behind, creating a duplicate branch with -0 suffix. Solution: Modified create_branch function to use git branch -m to rename the branch instead of creating a new one with git checkout -b. Added test case to verify the original branch is properly renamed.
1 parent 00f029f commit 72bab73

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

bin/gitstack.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function create_branch() {
8383
exit 0
8484
fi
8585

86-
# Create new stack branch
86+
# Create new stack branch by renaming current branch
8787
local new_branch="${current_branch}-0"
8888

8989
# Check if the new branch already exists
@@ -92,13 +92,13 @@ function create_branch() {
9292
exit 1
9393
fi
9494

95-
echo "Creating stack branch: $new_branch"
96-
if ! git checkout -b "$new_branch"; then
97-
echo "Error: Failed to create branch '$new_branch'."
95+
echo "Converting branch to stack branch: $new_branch"
96+
if ! git branch -m "$new_branch"; then
97+
echo "Error: Failed to rename branch to '$new_branch'."
9898
exit 1
9999
fi
100100

101-
echo "Branch '$new_branch' successfully created and checked out."
101+
echo "Branch successfully converted to '$new_branch'."
102102
return 0
103103
fi
104104

bin/gitstack_test.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ function test_convert_to_stack() {
435435
fail "Failed to convert branch to stack, got '$current'"
436436
fi
437437

438+
# Verify the original branch no longer exists
439+
if git rev-parse --verify dj/my-feature &>/dev/null; then
440+
fail "Original branch 'dj/my-feature' still exists after conversion"
441+
else
442+
echo "✅ Original branch 'dj/my-feature' was properly renamed"
443+
fi
444+
438445
git checkout main 2>/dev/null || git checkout master 2>/dev/null
439446
git branch -D dj/my-feature-0
440447
}

0 commit comments

Comments
 (0)