fix(infer): build branch chain via cherry-pick with conflict rollback

Description

When appending to an existing stack, if a cherry-pick fails the rollback deletes new branches and ref files but never reverts the Next pointer already written to the existing ref — leaving a dangling pointer that corrupts the stack linked list.

Fix: track original state of modified refs before mutation, restore them in rollback().

Identified by @viktomas in !3236 (comment).

How to test

go test ./internal/commands/stack/infer/... -run TestCreateBranches -v

Merge request reports

Loading