Skip to content

undo: prevent restoring to root operation#9071

Open
VedantMadane wants to merge 1 commit intojj-vcs:mainfrom
VedantMadane:fix/jj-undo-root-operation
Open

undo: prevent restoring to root operation#9071
VedantMadane wants to merge 1 commit intojj-vcs:mainfrom
VedantMadane:fix/jj-undo-root-operation

Conversation

@VedantMadane
Copy link

@VedantMadane VedantMadane commented Mar 10, 2026

Fixes #8153

When there is only one non-root operation in history, jj undo would restore to the root operation which has no working copy, leaving the repo in an unusable state (many commands fail with "This command requires a working copy").

This prevents jj undo from restoring to the root operation and shows a helpful error message with a hint to use jj redo.

I read the discussion on the issue @martinvonz suggested warning when the current workspace no longer exists (in cli_util.rs). The current implementation takes the simpler approach of blocking undo to root, but happy to rework this to check workspace existence instead if that's preferred.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added/updated tests to cover my changes
  • I fully understand the code that I am submitting (what it does,
    how it works, how it's organized), including any code drafted by an LLM.
  • For any prose generated by an LLM, I have proof-read and copy-edited with
    an eye towards deleting anything that is irrelevant, clarifying anything
    that is confusing, and adding details that are relevant. This includes,
    for example, commit descriptions, PR descriptions, and code comments.

Assisted-by: Cursor

@VedantMadane VedantMadane requested a review from a team as a code owner March 10, 2026 13:34
@martinvonz
Copy link
Member

Did you read the comments on the issue you linked to? Could you also fill out our PR template, especially since you said it's made with Cursor? Thanks

@PhilipMetzger
Copy link
Contributor

PhilipMetzger commented Mar 10, 2026

Made with Cursor

I think we should use Assisted-By: <Tool> like other projects for such attributions. Also you clearly didn't read the contributing guidelines from your title, since we in general don't use fix: except for commits related to the aptly named command.

@VedantMadane VedantMadane force-pushed the fix/jj-undo-root-operation branch from 4c4e480 to 800ac22 Compare March 11, 2026 05:46
When there is only one non-root operation in history, `jj undo` would
restore to the root operation which has no working copy, leaving the
repo in an unusable state (many commands fail with "This command
requires a working copy").

Prevent `jj undo` from restoring to the root operation and show a
helpful error message with a hint to use `jj redo`.

Fixes jj-vcs#8153
@VedantMadane VedantMadane force-pushed the fix/jj-undo-root-operation branch from 800ac22 to 51090b3 Compare March 11, 2026 06:50
@VedantMadane VedantMadane changed the title fix: prevent jj undo from restoring to root operation undo: prevent restoring to root operation Mar 11, 2026
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.

jj undo restoring to root operation puts repo in unusable state

3 participants