From 7ade8f058ec91ebdbbcdc8fc2ede5ee82576fbd6 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Fri, 25 May 2012 13:08:01 +0400 Subject: [PATCH] [git] Don't notify if user cancels cherry-pick, unless there were successful cherry-picks in the queue. +tests --- .../history/browser/GitCherryPicker.java | 4 ++ .../cherrypick/GitCherryPickTest.groovy | 3 ++ .../GitNotCommittingCherryPickTest.groovy | 46 ++++++++++++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/src/git4idea/history/browser/GitCherryPicker.java b/plugins/git4idea/src/git4idea/history/browser/GitCherryPicker.java index b52eb745d0d2..d938c0d03099 100644 --- a/plugins/git4idea/src/git4idea/history/browser/GitCherryPicker.java +++ b/plugins/git4idea/src/git4idea/history/browser/GitCherryPicker.java @@ -187,6 +187,10 @@ public class GitCherryPicker { } private void notifyCommitCancelled(@NotNull GitCommit commit, @NotNull List successfulCommits) { + if (successfulCommits.isEmpty()) { + // don't notify about cancelled commit. Notify just in the case when there were already successful commits in the queue. + return; + } String description = commitDetails(commit); description += getSuccessfulCommitDetailsIfAny(successfulCommits); myPlatformFacade.getNotificator(myProject).notifyWeakWarning("Cherry-pick cancelled", description, null); diff --git a/plugins/git4idea/tests/git4idea/cherrypick/GitCherryPickTest.groovy b/plugins/git4idea/tests/git4idea/cherrypick/GitCherryPickTest.groovy index fd905c4db05d..82cb52ef6f2a 100644 --- a/plugins/git4idea/tests/git4idea/cherrypick/GitCherryPickTest.groovy +++ b/plugins/git4idea/tests/git4idea/cherrypick/GitCherryPickTest.groovy @@ -37,6 +37,7 @@ import static git4idea.test.MockGit.OperationName.CHERRY_PICK import static git4idea.test.MockGit.commitMessageForCherryPick import static junit.framework.Assert.assertEquals import static junit.framework.Assert.assertTrue +import git4idea.test.TestNotificator /** * Common parent for all tests on cherry-pick @@ -60,6 +61,7 @@ hint: and commit the result with 'git commit' GitCherryPicker myCherryPicker GitLightRepository myRepository GitLightRepository.Commit myInitialCommit + TestNotificator myTestNotificator static final LOCAL_CHANGES_OVERWRITTEN_BY_CHERRY_PICK = """ @@ -83,6 +85,7 @@ hint: and commit the result with 'git commit' myRepository = new GitLightRepository() myRepositoryManager.add(myRepository) myInitialCommit = myRepository.commit("initial") + myTestNotificator = myPlatformFacade.getNotificator(myProject) as TestNotificator; } GitCommit commit(String commitMessage = "plain commit") { diff --git a/plugins/git4idea/tests/git4idea/cherrypick/GitNotCommittingCherryPickTest.groovy b/plugins/git4idea/tests/git4idea/cherrypick/GitNotCommittingCherryPickTest.groovy index ebe430df1f12..898318f4ff41 100644 --- a/plugins/git4idea/tests/git4idea/cherrypick/GitNotCommittingCherryPickTest.groovy +++ b/plugins/git4idea/tests/git4idea/cherrypick/GitNotCommittingCherryPickTest.groovy @@ -18,6 +18,7 @@ package git4idea.cherrypick import com.intellij.notification.NotificationType import git4idea.history.browser.GitCherryPicker import git4idea.history.browser.GitCommit +import git4idea.test.GitLightRepository import git4idea.test.MockGit import git4idea.test.MockVcsHelper import org.junit.Before @@ -25,7 +26,6 @@ import org.junit.Test import static git4idea.test.MockGit.OperationName.CHERRY_PICK import static junit.framework.Assert.* -import git4idea.test.GitLightRepository /** * Tests for {@link GitCherryPicker}, when the "auto-commit on cherry-pick" option is deselected. @@ -57,6 +57,50 @@ class GitNotCommittingCherryPickTest extends GitCherryPickTest { // notification is shown from the successful commit, can't check from here } + @Test + void "cancel in commit dialog shouldn't show a notification"() { + GitCommit commit = commit() + + myGit.registerOperationExecutors(new MockGit.SuccessfulCherryPickExecutor(myRepository, commit)) + CancelCommitDialogHandler handler = new CancelCommitDialogHandler() + myVcsHelper.registerHandler(handler) + + invokeCherryPick(commit) + + assertTrue "Commit dialog was not shown", handler.wasCommitDialogShown() + assertNull "Notification should not be shown when cancelling a single commit", myTestNotificator.lastNotification + } + + @Test + void "cancel in 2nd commit dialog after successful commit should shown a notification"() { + GitCommit commit1 = commit() + GitCommit commit2 = commit() + + myGit.registerOperationExecutors(new MockGit.SimpleSuccessOperationExecutor(CHERRY_PICK, ""), + new MockGit.SimpleSuccessOperationExecutor(CHERRY_PICK, "")) + + int dialogNumber = 0; + MockVcsHelper.CommitHandler handler = new MockVcsHelper.CommitHandler() { + boolean commit(String commitMessage) { + dialogNumber++; + // answer OK in the first dialog, Cancel - in the second. + return dialogNumber == 1; + } + } + myVcsHelper.registerHandler(handler) + + invokeCherryPick([commit1, commit2]) + + assertEquals "Commit dialog shown wrong number of times", 2, dialogNumber + assertNotificationShown("Cherry-pick cancelled", + """ + ${commitDetails(commit2)} +
+ However cherry-pick succeeded for the following commit:
+ ${commitDetails(commit1)} + """, NotificationType.WARNING) + } + @Test void "dirty tree, conflicting with commit, then show error"() { myGit.registerOperationExecutors(new MockGit.SimpleErrorOperationExecutor(CHERRY_PICK, LOCAL_CHANGES_OVERWRITTEN_BY_CHERRY_PICK))