Skip to content

feat: add undo command#20

Merged
boneskull merged 4 commits intomainfrom
undo
Feb 4, 2026
Merged

feat: add undo command#20
boneskull merged 4 commits intomainfrom
undo

Conversation

@boneskull
Copy link
Copy Markdown
Owner

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 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.

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).
Copilot AI review requested due to automatic review settings February 4, 2026 02:33
@boneskull
Copy link
Copy Markdown
Owner Author

Stack


Managed by gh-stack

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/undo snapshot format + persistence under .git/stack-undo/ (with archival to done/).
  • Adds gh stack undo command 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
Copilot AI review requested due to automatic review settings February 4, 2026 03:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@boneskull boneskull merged commit 2ad9b1b into main Feb 4, 2026
7 checks passed
@boneskull boneskull deleted the undo branch February 4, 2026 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants