Skip to content

Commit 5127d15

Browse files
authored
Merge pull request #1 from dagjomar/cursor/review-project-and-implement-improvement-cb42
Cursor/review project and implement improvement cb42
2 parents c28325a + dc3a118 commit 5127d15

4 files changed

Lines changed: 78 additions & 1 deletion

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Git Stack is a simple, no-frills command-line utility that makes managing stacke
1919

2020
- **Delete Branch Stacks:** Force-delete entire stacks of branches efficiently.
2121

22+
- **Push Branch Stacks:** Force-push all branches in a stack to remote with a single command.
23+
2224
## Installation
2325

2426
1. **Clone the Repository:**
@@ -79,6 +81,14 @@ Alternatively, to interactively delete the current branch's stack:
7981

8082
This command prompts for confirmation before deleting the stack.
8183

84+
- **Push a Branch Stack:**
85+
86+
```bash
87+
git stack push [base_name]
88+
```
89+
90+
Force-pushes all branches in a stack to the remote repository. If no base name is provided, it uses the current branch's stack.
91+
8292
## TODOs
8393
- Create better usage examples and use cases explaining how to best us it in a normal workflow
8494
- Create command to manage rebasing

TODO.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
## Advanced Stack Operations
2424
- `git stack rebase` - Rebase entire stack onto main
2525
- `git stack squash` - Combine all commits in a stack
26-
- `git stack push` - Push all stack branches in order
26+
- `git stack push` - Push all stack branches in order (COMPLETED)
2727
- `git stack clean` - Remove merged branches from stack
2828
- Undo/redo support for stack operations
2929

bin/gitstack.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# gitstack.sh fix [stack] # <-- fix an unhealthy stack by rebasing divergent branches
1313
# gitstack.sh prev # <-- checkout previous branch in stack (e.g. feature-2 -> feature-1)
1414
# gitstack.sh next # <-- checkout next branch in stack (e.g. feature-2 -> feature-3)
15+
# gitstack.sh push [stack] # <-- force-push all branches in a stack to remote
1516
#
1617
# Description:
1718
# create -> Creates a new branch named "<base_name>-0".
@@ -23,6 +24,7 @@
2324
# fix -> Fix an unhealthy stack by rebasing divergent branches.
2425
# prev -> Checkout previous branch in stack (e.g. feature-2 -> feature-1).
2526
# next -> Checkout next branch in stack (e.g. feature-2 -> feature-3).
27+
# push -> Force-push all branches in a stack to remote (uses current stack if none specified).
2628
# -----------------------------------------------------------------------------
2729

2830
function usage() {
@@ -38,6 +40,7 @@ function usage() {
3840
echo " $0 fix [stack] (Fix an unhealthy stack by rebasing divergent branches)"
3941
echo " $0 prev (Checkout previous branch in stack)"
4042
echo " $0 next (Checkout next branch in stack)"
43+
echo " $0 push [stack] (Force-push all branches in a stack to remote)"
4144
echo
4245
echo "Commands:"
4346
echo " create Creates a new branch named '<base_name>-0'."
@@ -49,6 +52,7 @@ function usage() {
4952
echo " fix Fix an unhealthy stack by rebasing divergent branches."
5053
echo " prev Checkout previous branch in stack (e.g. feature-2 -> feature-1)."
5154
echo " next Checkout next branch in stack (e.g. feature-2 -> feature-3)."
55+
echo " push Force-push all branches in a stack to remote. Uses current stack if none specified."
5256
exit 1
5357
}
5458

@@ -906,6 +910,9 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
906910
next)
907911
next_stack
908912
;;
913+
push)
914+
fp_stack "$@"
915+
;;
909916
*)
910917
usage
911918
;;

bin/gitstack_test.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,65 @@ function test_convert_to_stack() {
439439
git branch -D dj/my-feature-0
440440
}
441441

442+
# Test push command functionality
443+
function test_push_command() {
444+
echo "Testing push command..."
445+
446+
# Set up a fake remote to test pushing
447+
git init --bare "$TEST_DIR/remote.git"
448+
git remote add origin "$TEST_DIR/remote.git"
449+
450+
# Create a test stack with multiple branches
451+
git checkout main 2>/dev/null || git checkout master 2>/dev/null
452+
"$SCRIPT_DIR/gitstack.sh" create push-test
453+
echo "test1" > test1.txt
454+
git add test1.txt
455+
git commit -m "test1"
456+
457+
"$SCRIPT_DIR/gitstack.sh" increment
458+
echo "test2" > test2.txt
459+
git add test2.txt
460+
git commit -m "test2"
461+
462+
"$SCRIPT_DIR/gitstack.sh" increment
463+
echo "test3" > test3.txt
464+
git add test3.txt
465+
git commit -m "test3"
466+
467+
# Test push from current stack branch
468+
if "$SCRIPT_DIR/gitstack.sh" push 2>&1 | grep -q "Successfully force-pushed all branches"; then
469+
echo "✅ push command successfully pushed from current stack"
470+
else
471+
fail "push command failed to push from current stack"
472+
fi
473+
474+
# Verify all branches were pushed to remote
475+
local remote_branches
476+
remote_branches=$(git ls-remote --heads origin | awk '{print $2}' | sed 's|refs/heads/||')
477+
478+
if echo "$remote_branches" | grep -q "push-test-0" && \
479+
echo "$remote_branches" | grep -q "push-test-1" && \
480+
echo "$remote_branches" | grep -q "push-test-2"; then
481+
echo "✅ All stack branches successfully pushed to remote"
482+
else
483+
fail "Not all stack branches were pushed to remote"
484+
fi
485+
486+
# Test push with explicit stack name from different branch
487+
git checkout main 2>/dev/null || git checkout master 2>/dev/null
488+
if "$SCRIPT_DIR/gitstack.sh" push push-test 2>&1 | grep -q "Successfully force-pushed all branches"; then
489+
echo "✅ push command with explicit stack name worked"
490+
else
491+
fail "push command with explicit stack name failed"
492+
fi
493+
494+
# Clean up
495+
git remote remove origin
496+
rm -rf "$TEST_DIR/remote.git"
497+
"$SCRIPT_DIR/gitstack.sh" delete -f push-test
498+
rm -f test1.txt test2.txt test3.txt
499+
}
500+
442501
# Run all tests
443502
function run_all_tests() {
444503
source_gitstack
@@ -450,6 +509,7 @@ function run_all_tests() {
450509
test_fix_command
451510
test_stack_navigation
452511
test_convert_to_stack
512+
test_push_command
453513
}
454514

455515
# Create a temporary test directory

0 commit comments

Comments
 (0)