mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-99849 Force checkout as new branch reports "branch already exists"
Mark repository as successful if force checkout succeedes. Add a test.
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import git4idea.GitPlatformFacade;
|
||||
import git4idea.GitVcs;
|
||||
import git4idea.commands.*;
|
||||
@@ -129,7 +130,12 @@ class GitCheckoutOperation extends GitBranchOperation {
|
||||
}
|
||||
}
|
||||
else if (smartCheckoutDecision == GitSmartOperationDialog.FORCE_EXIT_CODE) {
|
||||
return checkoutOrNotify(allConflictingRepositories, myStartPointReference, myNewBranch, true);
|
||||
boolean forceCheckoutSucceeded = checkoutOrNotify(allConflictingRepositories, myStartPointReference, myNewBranch, true);
|
||||
if (forceCheckoutSucceeded) {
|
||||
markSuccessful(ArrayUtil.toObjectArray(allConflictingRepositories, GitRepository.class));
|
||||
refresh(ArrayUtil.toObjectArray(allConflictingRepositories, GitRepository.class));
|
||||
}
|
||||
return forceCheckoutSucceeded;
|
||||
}
|
||||
else {
|
||||
fatalLocalChangesError(myStartPointReference);
|
||||
|
||||
@@ -412,6 +412,29 @@ class GitBranchWorkerTest extends GitLightTest {
|
||||
assertNotNull "Rollback proposal was not shown", rollbackMsg
|
||||
}
|
||||
|
||||
@Test
|
||||
void "Force checkout in case of local changes that would be overwritten by checkout"() {
|
||||
// IDEA-99849
|
||||
prepareLocalChangesOverwrittenBy(myUltimate)
|
||||
|
||||
String errorMessage = null;
|
||||
String successMessage = null;
|
||||
def uiHandler = [
|
||||
showSmartOperationDialog: { Project p, List<Change> cs, String op, boolean force ->
|
||||
GitSmartOperationDialog.FORCE_EXIT_CODE;
|
||||
},
|
||||
notifySuccess: { String message -> successMessage = message },
|
||||
notifyError: { String title, String message -> errorMessage = message }
|
||||
] as GitBranchUiHandler
|
||||
GitBranchWorker brancher = new GitBranchWorker(myProject, myPlatformFacade, myGit, uiHandler)
|
||||
brancher.checkoutNewBranchStartingFrom("new_branch", "feature", myRepositories)
|
||||
|
||||
assertNull("Error notification is unexpected, but was: $errorMessage", errorMessage)
|
||||
assertEquals("Notification about successful branch creation is incorrect",
|
||||
"Checked out new branch <b><code>new_branch</code></b> from <b><code>feature</code></b>", successMessage)
|
||||
assertCurrentBranch("new_branch")
|
||||
}
|
||||
|
||||
@Test
|
||||
public void "rollback of 'checkout branch as new branch' should delete branches"() {
|
||||
branchWithCommit(myRepositories, "feature")
|
||||
|
||||
Reference in New Issue
Block a user