Skip to content

feat: Add undo and revert commit functionality to workspace commits - #344

Merged
Ziinc merged 2 commits into
mainfrom
claude/undo-revert-commits-bqa40m
Aug 26, 2026
Merged

feat: Add undo and revert commit functionality to workspace commits#344
Ziinc merged 2 commits into
mainfrom
claude/undo-revert-commits-bqa40m

Conversation

@Ziinc

@Ziinc Ziinc commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds two new commit manipulation features to the Commits tab: "Undo commit" and "Revert commit". These operations allow users to modify their workspace commit history with different semantics.

Key Changes

Backend (Rust)

  • jj_undo_commit() in src-tauri/src/jj.rs: Implements undoing the latest commit in a workspace's lineage by abandoning it and folding its changes back into the working copy. Validates that:
    • The commit is the current tip (@-), not the working copy itself
    • The commit is not on the target branch
    • Commits must be undone sequentially from the tip backwards
  • jj_revert_commit() in src-tauri/src/jj.rs: Creates a new commit that reverses the changes of any target commit (except the working copy) using a 3-way merge strategy. The new commit is created on top of the current tip with a "Revert" prefix in its description.
  • Core API wrappers in src-tauri/src/core/commits.rs: Added undo_commit() and revert_commit() functions that handle workspace lookup and path resolution before delegating to jj operations.
  • Tauri commands in src-tauri/src/commands/workspace.rs: Exposed undo_commit and revert_commit as async commands callable from the frontend.

Frontend (TypeScript/React)

  • API bindings in src/lib/api-extra.ts: Added undoCommit() and revertCommit() functions to invoke the new Tauri commands.
  • UI components in src/components/CommitDiffViewer.tsx:
    • Added handleUndo() and handleRevert() handlers with confirmation dialogs
    • "Undo commit" button appears only on the latest workspace commit (isFirst)
    • "Revert commit" button appears on all real commits except the working copy
    • Both operations trigger appropriate toast notifications on success/failure
    • Undo removes the commit with animation; revert refreshes the commit list

Tests

  • Unit tests in src/components/CommitDiffViewer.undoRevert.test.tsx: Comprehensive test suite covering:
    • Undo button visibility (only on latest commit)
    • Revert button visibility (all commits except working copy)
    • Successful undo and revert operations with API mocking
    • Cancellation behavior when user declines confirmation
  • Integration tests in src-tauri/tests/core_commits_test.rs:
    • test_undo_commit_only_allows_latest_commit_sequentially: Validates sequential undo constraint
    • test_undo_commit_rejects_commit_on_target_branch: Ensures target branch commits cannot be undone
    • test_revert_commit_creates_backout_commit: Verifies revert creates proper backout commit
    • test_revert_commit_rejects_working_copy: Prevents reverting the working copy
  • Screenshot/E2E test in scripts/screenshot/specs/undo-revert-commit.spec.tsx: Full user workflow demonstrating creating commits, undoing, reverting, and the resulting state changes.

Notable Implementation Details

  • Undo semantics: Implemented as validated abandon—the commit is removed and its changes are folded back into the working copy, exactly reversing the commit operation. Only the tip can be undone to maintain a clear sequential workflow.
  • Revert semantics: Creates a new commit using 3-way merge (commit's tree vs. parent tree, merged onto current tip), producing a proper backout commit that can itself be undone if needed.
  • Workspace reconciliation: Both operations call reconcile_all_workspaces_after_rewrite() to handle potential working-copy rewrites across all workspaces.
  • UI constraints: The "Undo commit" button is only shown on the first (latest) commit in the list, while "Revert commit" is available on all real commits, making the distinction clear
    https://claude.ai/code/session_017D1cm4fRhCRLPAnNNPKRd3

Undo removes the latest commit in a workspace's own lineage (not the
working copy, not a commit on the target branch), enforced sequentially
from the tip via a validated abandon. Revert creates a new commit that
reverses any real commit's changes on top of the workspace's current
tip, restricted only from targeting the working copy itself.
@github-actions

github-actions Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

@Ziinc Ziinc changed the title Add undo and revert commit functionality to workspace commits feat: Add undo and revert commit functionality to workspace commits Aug 26, 2026
…ting max-lines

Rebasing onto main picked up the project-wide switch to 2-space indentation
(rustfmt.toml tab_spaces=2); ran cargo fmt + biome format to match. Also
disabled the max-lines rule in src/lib/api-extra.ts, which already exceeded
the 500-line limit on main before this branch's additions.
@Ziinc
Ziinc merged commit bebf119 into main Aug 26, 2026
13 of 14 checks passed
@Ziinc
Ziinc deleted the claude/undo-revert-commits-bqa40m branch August 26, 2026 20:51
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