Skip to content

Commit e127ec0

Browse files
committed
fix(stack): update existing branch pointer when reusing branch name
CRITICAL FIX: When pushing to a stack with --branch specifying an existing branch name, we were: 1. Skipping branch creation (correct) 2. Adding metadata entry pointing to new commit (correct) 3. BUT leaving the Git branch pointing to old commit (BUG!) This caused stack corruption on next ca sync/ca validate, which would 'fix' the metadata back to the stale commit, dropping user's work. Now we call update_branch_to_commit() to fast-forward the existing branch to the new commit, keeping Git refs and metadata in sync. Scenario: - User: ca push --branch feat-auth <commit1> - User: ca push --branch feat-auth <commit2> # Reusing same name - Before: feat-auth branch still at commit1, metadata at commit2 → corruption - After: feat-auth branch updated to commit2, metadata at commit2 → consistent
1 parent 6a6b59d commit e127ec0

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/stack/manager.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,19 @@ impl StackManager {
468468
// 🆕 CREATE ACTUAL GIT BRANCH from the specific commit
469469
// Check if branch already exists
470470
if self.repo.branch_exists(&branch) {
471-
// Branch already exists, skip creation
471+
// Branch already exists - update it to point to the new commit
472+
// This is critical: if we skip this, the branch points to the old commit
473+
// but metadata points to the new commit, causing stack corruption
474+
self.repo
475+
.update_branch_to_commit(&branch, &commit_hash)
476+
.map_err(|e| {
477+
CascadeError::branch(format!(
478+
"Failed to update existing branch '{}' to commit {}: {}",
479+
branch,
480+
&commit_hash[..8],
481+
e
482+
))
483+
})?;
472484
} else {
473485
// Create the branch from the specific commit hash
474486
self.repo

0 commit comments

Comments
 (0)