feat: Add undo and revert commit functionality to workspace commits - #344
Merged
Conversation
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.
Contributor
|
🚀 Web preview: https://preview-344.treq-9zy.pages.dev |
…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.
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.
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()insrc-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:@-), not the working copy itselfjj_revert_commit()insrc-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.src-tauri/src/core/commits.rs: Addedundo_commit()andrevert_commit()functions that handle workspace lookup and path resolution before delegating to jj operations.src-tauri/src/commands/workspace.rs: Exposedundo_commitandrevert_commitas async commands callable from the frontend.Frontend (TypeScript/React)
src/lib/api-extra.ts: AddedundoCommit()andrevertCommit()functions to invoke the new Tauri commands.src/components/CommitDiffViewer.tsx:handleUndo()andhandleRevert()handlers with confirmation dialogsisFirst)Tests
src/components/CommitDiffViewer.undoRevert.test.tsx: Comprehensive test suite covering:src-tauri/tests/core_commits_test.rs:test_undo_commit_only_allows_latest_commit_sequentially: Validates sequential undo constrainttest_undo_commit_rejects_commit_on_target_branch: Ensures target branch commits cannot be undonetest_revert_commit_creates_backout_commit: Verifies revert creates proper backout committest_revert_commit_rejects_working_copy: Prevents reverting the working copyscripts/screenshot/specs/undo-revert-commit.spec.tsx: Full user workflow demonstrating creating commits, undoing, reverting, and the resulting state changes.Notable Implementation Details
reconcile_all_workspaces_after_rewrite()to handle potential working-copy rewrites across all workspaces.https://claude.ai/code/session_017D1cm4fRhCRLPAnNNPKRd3