mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
[git] Don't notify if user cancels cherry-pick, unless there were successful cherry-picks in the queue. +tests
This commit is contained in:
@@ -187,6 +187,10 @@ public class GitCherryPicker {
|
||||
}
|
||||
|
||||
private void notifyCommitCancelled(@NotNull GitCommit commit, @NotNull List<GitCommit> 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);
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -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)}
|
||||
<hr/>
|
||||
However cherry-pick succeeded for the following commit:<br/>
|
||||
${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))
|
||||
|
||||
Reference in New Issue
Block a user