Repository navigation
Conversation
bamaer
left a comment
There was a problem hiding this comment.
Thanks for the fix, @dajiaohuang. Checking the path's status inside restorePathFromCommit covers both file actions and the git rm branch, and isClean() is the right check: it also catches an untracked file at the path, which checkout would overwrite.
Refuse before the confirmation, not after
Right now the user confirms "Revert 'x' to the version before commit …?", clicks Yes, and then gets an ErrorDialog with a stack trace. This is a precondition, not an error. Please:
- Add a public helper to
UIGit, e.g.hasLocalChanges(String path), using the samestatus().addPath(..).call().isClean()check. - In
GitPerspective.revertFile()andcherryPickFile(), call it beforeconfirmFileActionand show a warningMessageBox. Load its text frommessages_en_US.properties, for example''{0}'' has uncommitted changes. Commit or stash them first. - Keep the check in
restorePathFromCommitas a backstop.
Tests
- Another dirty file does not block the restore. The description says so, but no test covers it.
- Reverting a commit that added the file while that file has local edits. This is the
git rmbranch. - An untracked file at the path when reverting a commit that deleted it.
testRestorePathFromCommitPreservesStagedChanges: assert the message as the unstaged test does, so that an unrelated exception does not pass the test.
Optional, pre-existing
revertCommit() and cherryPickCommit() build the "repository is not clean" MessageBox but never call open(). On a dirty repository those actions return without saying anything. It's a one-line fix in each method if you're in this code anyway; otherwise it can go in a separate issue.
|
Thanks for the detailed review. I pushed commit Validation: the targeted Maven build completed successfully; |
Summary
The Git perspective's file-level Revert and Cherry-pick actions both use
UIGit.restorePathFromCommit, which could replace the selected file while staged or unstaged local edits were present. Check the selected path's JGit status before restoring or removing it and refuse with a commit-or-stash message when that path is dirty. Unrelated dirty files do not block the operation.Fixes #8935.
Verification
mvnw.cmd -B -pl plugins/misc/git spotless:applymvnw.cmd -B -Pskip-uitest -pl plugins/misc/git -am -Dtest=UIGitTest -Dsurefire.failIfNoSpecifiedTests=false test(Java 21): 63 tests passed, 0 failures, 0 errors.