gh stack modify: modify fails when merged branches have been pruned
Looks like modify can't deal with pruned branches once they have been merged.
See below output:
➜ token-scanning-service git:(aerendel/fix-generic-secrets-metadata) gh stack modify
✗ failed to apply modifications: building snapshot: resolving branch SHAs: failed to run git: fatal: ambiguous argument 'aerendel/mixed-content-types1': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Observed behavior:
The bottom of my stack has been merged and the branch pruned so it doesn't exist locally or remotely anymore (not unusual once a branch is merged), and all gh stack modify operations fail to save. Any operation will fail, wether it's renaming a branch, reorganizing, dropping a branch, etc.
Repro:
- Make a stack with 2 or 3 layers
- Merge the first layer
- Delete the first layer's branch locally (or just answer Yes to gh stack's prune prompt)
- Run
gh stack modifyand try to save any modify operation
Thanks for reporting this. I reproduced the failure on current main and am working on a focused fix that skips merged branches only when their local refs have been pruned. The regression coverage also keeps missing active branches as errors and verifies that abort does not recreate a deliberately pruned merged branch. I will open a PR once the final checks are complete.
I hit the same issue. I'm using gh 2.97.0 and gh-stack v0.1.0
Any workaround on how to make that work? unstacking does not work due to
Pull requests #xxx, #xxx cannot be removed from this stack <- those are the PRs that got merged
Hello @Pybsama Did you manage to complete the final checks? If so, could you share the PR link? I’d love to test it!
Final checks are complete on current main (2bd699a), and the rebased handoff is available here:
- Branch: https://github.com/Pybsama/gh-stack/tree/codex/skip-pruned-merged-modify-snapshots
- GitHub Verified commit: https://github.com/Pybsama/gh-stack/commit/f5ef73a9f28d6dc6560a0e0f0ddfa1bf02abfb0b
The fix skips only merged branches whose local refs were pruned, keeps the complete stack metadata for recovery, and still rejects missing active branches. The final review also caught and closed a same-named-tag edge case: snapshot resolution now checks that each active local branch exists and resolves only refs/heads/<branch>.
Fresh validation on Go 1.26.5:
go vet ./...go test -race -count=20 ./internal/modify -run TestBuildSnapshotgo test -race -count=1 ./...go build ./...- formatting and diff checks
- independent re-review: 0 Critical / 0 Important / 0 Minor, Ready
There is no PR link because this repository currently has pullRequestCreationPolicy=COLLABORATORS_ONLY and my upstream permission is READ. A collaborator can use the branch directly; I cannot open the upstream PR myself.
To test without replacing an installed extension:
git clone --branch codex/skip-pruned-merged-modify-snapshots https://github.com/Pybsama/gh-stack.git
cd gh-stack
go build -o gh-stack .
# From the repository that reproduces #146:
/path/to/this/clone/gh-stack modify
@vmaerten @martpie, this is ready for your pruned-branch reproduction.
What worked for me, was to recreate the branch (as a dummy). The stack will skip it anyway for rebasing
What worked for me, was to recreate the branch (as a dummy). The stack will skip it anyway for rebasing
Yep, I did it with:
git branch -f deleted-branch main
I've run into this issue a few time this week. I think it's being made worse as gh stack sync prompts to prune merged branches with a default of Yes. I think in the long term this is the correct default to have, but currently with this bug open it creates a bad user experience.