rebase --upstack reports success and exits 0 when a dirty worktree blocks the rebase
Version
gh stack v0.0.5
What happened
gh stack rebase --upstack printed a success line for a branch it did not
rebase, then exited 0. Unstaged changes in the working tree had blocked the
git rebase.
Output:
Rebasing branches in order, starting from chore/dependabot-sha-pins to chore/update-actions
✓ Rebased chore/dependabot-sha-pins onto main
✓ Rebased chore/update-actions onto chore/dependabot-sha-pins
All upstack branches from chore/dependabot-sha-pins rebased locally with main
To push up your changes, run `gh stack push`
The top branch had not moved:
$ git merge-base --is-ancestor chore/dependabot-sha-pins chore/update-actions; echo $?
1
gh stack view --json reported the true state, "needsRebase": true on the top
branch. So the command's output disagrees with the work it did.
The same rebase by hand showed the cause at once:
$ git rebase chore/dependabot-sha-pins
error: cannot rebase: You have unstaged changes.
error: Please commit or stash them.
The unstaged changes were line endings only: core.autocrlf=true on Windows,
LF in the index. git diff showed nothing, so they were easy to miss.
Reproduction
- Create a stack of two branches, each with a commit.
- Leave an unstaged change in the working tree.
- Check out the bottom branch and add a commit.
- Run
gh stack rebase --upstack.
Observed: a success line for every branch, exit 0, branches unmoved.
Expected: a non-zero exit, or an error naming the dirty worktree, and no
✓ Rebased ... line for a branch that did not move.
Why it matters
The success line and the 0 exit code both say the stack is sound, so the next
step is gh stack push and then a merge. By then the branches have split
histories. You see the failure only if you check needsRebase in
gh stack view --json yourself.
A check for a clean worktree before the rebase starts would catch this, as exit code 3 already catches conflicts.
v0.1.0 fixes this. I ran the same steps again on v0.1.0:
✗ could not start rebase of repro-bottom onto <trunk>: failed to run git: error: cannot rebase: You have unstaged changes.
error: Please commit or stash them.
Exit code 1. gh stack view --json still shows "needsRebase": true on the top
branch, which now agrees with the output. With a clean worktree the same command
rebases both branches, exits 0, and git merge-base --is-ancestor confirms the
ancestry.
I suspect the ancestry check from "verify the resulting ancestry before reporting success or pushing" in the v0.1.0 stale-trunk fix catches this case too, since it catches any rebase that did not happen.
One correction to the report above: I read the original exit code through a
pipe, so I measured the exit status of tail, not of gh stack. Treat the
"exited 0" claim as unverified. The false ✓ line and the unmoved branch were
real, and I confirmed both with git merge-base.
Closing. Thanks.