Conversation
Implements `gh stack undo` to restore branches to their pre-operation state after cascade, submit, or sync commands. Key features: - Captures snapshots before destructive ops in `.git/stack-undo/` - Auto-stashes uncommitted changes (including untracked files) - Restores branch refs, stack config, and stashed changes on undo - Supports `--dry-run` to preview and `--force` to skip confirmation - Archives used snapshots to `done/` subdirectory for audit Also adds new git operations: `Stash()`, `StashPop()`, `SetBranchRef()`, and `CreateBranchAt()` to support the restore functionality.
Documents the new undo command including its purpose, what it restores, and available flags (--force, --dry-run).
Owner
Author
Stack
Managed by gh-stack |
There was a problem hiding this comment.
Pull request overview
Adds a new gh stack undo command and supporting infrastructure to restore local branch/config state after destructive operations (cascade/submit/sync), with documentation and test coverage.
Changes:
- Introduces an
internal/undosnapshot format + persistence under.git/stack-undo/(with archival todone/). - Adds
gh stack undocommand to restore branch refs, stack config, recreate deleted branches, and restore auto-stashed changes. - Captures undo snapshots (and auto-stashes when dirty) before cascade/submit/sync; updates README and e2e/unit tests accordingly.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/undo/undo.go | Snapshot model + Save/Load/List/Archive helpers for undo state. |
| internal/undo/undo_test.go | Unit tests covering snapshot persistence, listing, archiving, deletion, and fields. |
| internal/git/git.go | Adds branch ref setters/creators and stash helpers used by undo/auto-stash. |
| cmd/undo.go | Implements gh stack undo restore flow, dry-run/force flags, and config restoration. |
| cmd/cascade.go | Saves undo snapshot and auto-stashes before cascading; adds snapshot capture helpers. |
| cmd/submit.go | Saves undo snapshot before submit (when not dry-run); removes “dirty tree” hard-fail. |
| cmd/sync.go | Saves undo snapshot before sync (when not dry-run). |
| e2e/undo_test.go | End-to-end tests for undo behavior (restore refs/config/original branch/stash, archive, etc.). |
| e2e/submit_test.go | Updates submit dirty-worktree test expectations. |
| e2e/error_cases_test.go | Updates cascade dirty-tree behavior to expect auto-stash + success. |
| README.md | Documents the new undo command and flags. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use stable stash commit hash instead of stash@{0} ref
- Restore auto-stashed changes after successful operations
- Use nanosecond precision for snapshot timestamps to avoid collisions
- Fix StashPop to use 'git stash apply' for commit hash support
- Update test names to accurately reflect behavior
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Persist stash ref in CascadeState so continue/abort can restore it - Add git.AbbrevSHA() helper to safely abbreviate SHAs without panicking - Update StashPop to drop stash entry after successful apply (prevents accumulation) - Use defer in sync.go to restore stash on all error paths (except conflicts) - Restore stash on non-conflict errors in cascade/submit - Update continue.go and abort.go to restore stash from state
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
docs: add undo command to README
Documents the new undo command including its purpose, what it restores,
and available flags (--force, --dry-run).
feat: add undo command to restore state after destructive operations
Implements
gh stack undoto restore branches to their pre-operationstate after cascade, submit, or sync commands. Key features:
.git/stack-undo/--dry-runto preview and--forceto skip confirmationdone/subdirectory for auditAlso adds new git operations:
Stash(),StashPop(),SetBranchRef(),and
CreateBranchAt()to support the restore functionality.