Shared branch creation and verification logic for sequential and parallel task execution - handles git operations, HEAD verification, and MODE-specific behavior
Invoked by sequential-phase-task and parallel-phase-task after task implementation to create and verify git-spice branch.
Step 1: Stage and create branch
git add .
gs branch create {RUN_ID}-task-{TASK_ID}-{TASK_NAME} -m "{COMMIT_MESSAGE}"
Step 2: Verify based on MODE
MODE: sequential - Verify HEAD points to expected branch:
CURRENT=$(git rev-parse --abbrev-ref HEAD)
EXPECTED="{RUN_ID}-task-{TASK_ID}-{TASK_NAME}"
[ "$CURRENT" = "$EXPECTED" ] || { echo "ERROR: HEAD=$CURRENT, expected $EXPECTED"; exit 1; }
MODE: parallel - Detach HEAD (makes branch accessible in parent repo):
git switch --detach
CURRENT=$(git rev-parse --abbrev-ref HEAD)
[ "$CURRENT" = "HEAD" ] || { echo "ERROR: HEAD not detached ($CURRENT)"; exit 1; }
| Rationalization | Why It's Wrong |
|---|---|
| "Verification is optional" | Silent failures lose work |
| "Skip detach in parallel mode" | Breaks worktree cleanup |
| "Branch create errors are obvious" | Silent failures aren't detected until cleanup fails |
| "Detach can happen later" | Cleanup runs in parent repo - branch must be accessible |
| "HEAD verification adds overhead" | <100ms cost prevents hours of lost work debugging |
git add fails:
ls -la .gitgs branch create fails:
git branch | grep {RUN_ID}-task-{TASK_ID}gs repo sync to fix stategs lsHEAD verification fails (sequential mode):
gs branch create should checkout new branch automaticallyHEAD verification fails (parallel mode):
git switch --detach should detach HEADgit --version