gh-stack icon indicating copy to clipboard operation
gh-stack copied to clipboard

gh stack modify: modify fails when merged branches have been pruned

Open Aerendel opened this issue 5 months ago • 8 comments

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:

  1. Make a stack with 2 or 3 layers
  2. Merge the first layer
  3. Delete the first layer's branch locally (or just answer Yes to gh stack's prune prompt)
  4. Run gh stack modify and try to save any modify operation

Aerendel avatar Jun 25 '26 22:06 Aerendel

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.

Pybsama avatar Jul 31 '26 08:07 Pybsama

I hit the same issue. I'm using gh 2.97.0 and gh-stack v0.1.0

pedromatosogibb avatar Aug 02 '26 05:08 pedromatosogibb

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

martpie avatar Aug 24 '26 14:08 martpie

Hello @Pybsama Did you manage to complete the final checks? If so, could you share the PR link? I’d love to test it!

vmaerten avatar Aug 26 '26 09:08 vmaerten

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 TestBuildSnapshot
  • go 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.

Pybsama avatar Aug 28 '26 19:08 Pybsama

What worked for me, was to recreate the branch (as a dummy). The stack will skip it anyway for rebasing

Netail avatar Sep 04 '26 07:09 Netail

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

alexreinking avatar Sep 05 '26 16:09 alexreinking

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.

81reap avatar Sep 26 '26 17:09 81reap