use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflictTest method testSwitchBranchWhenRepoInConflict_succeed_1.
/**
* <p><b>Description:</b> try to switch branch from Git Staging when repo is in conflict state.
* This should succeed.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
@Test
public void testSwitchBranchWhenRepoInConflict_succeed_1() throws Exception {
// Push test.txt from first repo
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "hellllo");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
push("", "");
// Commit test.txt from second repo
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
File file = new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
file.createNewFile();
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "teeeeeest");
;
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("conflict");
// Change file.txt file on the new branch
gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
gitAccess.setBranch("new_branch");
;
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/file.txt"), "altfel");
;
gitAccess.add(new FileStatus(GitChangeType.ADD, "file.txt"));
gitAccess.commit("commit on nnew branch");
// move to main
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
// change file.txt to create checkout conflict
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/file.txt"), "new changes");
;
gitAccess.add(new FileStatus(GitChangeType.ADD, "file.txt"));
// Pull to create conflict o text.txt
PullResponse pullResp = pull("", "", PullType.MERGE_FF, false);
assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullResp.toString());
// Simulate branch checkout from Git Staging
GitController gitController = new GitController(gitAccess);
BranchSelectionCombo branchesCombo = new BranchSelectionCombo(gitController);
branchesCombo.refresh();
SwingUtilities.invokeLater(() -> branchesCombo.setSelectedIndex(1));
flushAWT();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
assertEquals("Branch_switch_when_repo_in_conflict_error_msg", errMsg[0]);
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitCheckoutConflictTest method testSwitchBranchFromGitBranchManager_checkoutConflict_1.
/**
* <p><b>Description:</b> try to switch branch from Git Branch Manager.
* The branch witch generates a checkout conflict.</p>
* <p><b>Bug ID:</b> EXM-47439</p>
*
* @author sorin_carbunaru
*
* @throws Exception
*/
@Test
public void testSwitchBranchFromGitBranchManager_checkoutConflict_1() throws Exception {
// Push from first repo
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "hellllo");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("file test added");
push("", "");
// Change file on the new branch
gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
gitAccess.setBranch("new_branch");
writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "altfel");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("commit 2");
// move to main branch
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "new content");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
sleep(1000);
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
// Simulate branch checkout from Git Branch Manager view
GitTreeNode node = new GitTreeNode(new TreePath(new String[] { "refs", "heads", "new_branch" }));
node.setUserObject("refs/heads/new_branch");
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(node);
for (AbstractAction abstractAction : actionsForNode) {
if (abstractAction.getValue(AbstractAction.NAME).equals(Tags.CHECKOUT)) {
abstractAction.actionPerformed(null);
break;
}
}
sleep(1000);
Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
JButton yesButton = TestUtil.findButton(focusedWindow, translator.getTranslation(Tags.MOVE_CHANGES));
yesButton.doClick();
sleep(1000);
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
assertEquals("Branch_switch_checkout_conflict_error_msg", errMsg[0]);
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitControllerTest method testFailPushNotification.
/**
* For asynchronous tasks we always issue fail events when exceptions are thrown.
*
* @throws Exception If it fails.
*/
@Test
public void testFailPushNotification() throws Exception {
GitAccess mock = Mockito.mock(GitAccess.class);
// When Push will be invoked a runtime exception is thrown.
GitController ctrl = new GitController(mock);
StringBuilder b = new StringBuilder();
ctrl.addGitListener(new GitEventListener() {
@Override
public void operationSuccessfullyEnded(GitEventInfo info) {
b.append("E: " + info.toString()).append("\n");
}
@Override
public void operationFailed(GitEventInfo info, Throwable t) {
b.append("F: ").append(info.toString()).append("\n");
b.append(" ").append(t.getClass()).append("\n");
}
@Override
public void operationAboutToStart(GitEventInfo info) {
b.append("S: ").append(info.toString()).append("\n");
}
});
Future<?> push = ctrl.push();
push.get();
Assert.assertEquals("Not the expected events", "S: Status: null, message: Push_In_Progress GitEventInfo [Operation: PUSH].\n" + "F: Status: null, message: Push_failed: null GitEventInfo [Operation: PUSH].\n" + " class java.lang.NullPointerException\n" + "", b.toString());
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitPullCasesTest method testPullRebaseUncommittedChanges.
/**
* We had changes in X and Y locally, and an incoming change from remote on X.
* We committed X and tried to pull with rebase, and we got into this situation...
*
* @throws Exception
*/
@Test
public void testPullRebaseUncommittedChanges() throws Exception {
String local1Repository = "target/test-resources/GitPullCasesTest/testPullRebaseUncommittedChanges-rebase-local";
String local2Repository = "target/test-resources/GitPullCasesTest/testPullRebaseUncommittedChanges-rebase-local-second";
String remoteRepository = "target/test-resources/GitPullCasesTest/testPullRebaseUncommittedChanges-rebase-remote";
Repository local1Repo = createRepository(local1Repository);
Repository local2Repos = createRepository(local2Repository);
Repository remoteRepo = createRepository(remoteRepository);
bindLocalToRemote(local1Repo, remoteRepo);
bindLocalToRemote(local2Repos, remoteRepo);
// ----------------
// LOCAL 1
// ----------------
GitAccess instance = GitAccess.getInstance();
instance.setRepositorySynchronously(local1Repository);
// Create a file in the remote.
File remoteParent = new File(local1Repository);
remoteParent.mkdirs();
File local1File = new File(local1Repository, "test.txt");
setFileContent(local1File, "original");
instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
instance.commit("Primul");
push("", "");
File local1_2File = new File(local1Repository, "test_1_2.txt");
setFileContent(local1_2File, "original 1 2");
instance.add(new FileStatus(GitChangeType.ADD, "test_1_2.txt"));
instance.commit("Primul 1 2");
push("", "");
// ----------------
// LOCAL 2
// ----------------
instance.setRepositorySynchronously(local2Repository);
PullResponse pull = pull("", "", PullType.MERGE_FF, false);
assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
File local2File = new File(new File(local2Repository), "test.txt");
assertEquals("original", TestUtil.read(local2File.toURI().toURL()));
setFileContent(local2File, "changed in local 2");
instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
instance.commit("Al doilea");
push("", "");
// ----------------
// LOCAL 1
// ----------------
final StringBuilder pullWithConflicts = new StringBuilder();
final List<String> filesWithChanges = new ArrayList<>();
final List<String> messages = new ArrayList<>();
GitController pc = new GitController(GitAccess.getInstance()) {
@Override
protected void showPullFailedBecauseOfCertainChanges(List<String> files, String message) {
filesWithChanges.addAll(files);
messages.add(message);
}
@Override
protected void showPullSuccessfulWithConflicts(PullResponse response) {
pullWithConflicts.append(response);
}
};
final StringBuilder b = new StringBuilder();
TestUtil.collectPushPullEvents(pc, b);
// FIRST REPO
instance.setRepositorySynchronously(local1Repository);
setFileContent(local1File, "changed in local 1");
instance.add(new FileStatus(GitChangeType.ADD, "test.txt"));
instance.commit("Another");
// Another change, uncommitted
setFileContent(local1_2File, "updated 1 2");
pc.pull(PullType.REBASE).get();
assertEquals("[Pull_rebase_failed_because_uncommitted] FOR [test_1_2.txt]", messages + " FOR " + filesWithChanges);
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitPullCasesTest method testLockFailedExceptionHandler.
/**
* <p><b>Description:</b> Intercept {{LockFailedException}} when pulling and present it to the user.</p>
* <p><b>Bug ID:</b> EXM-49039</p>
*
* @author sorin_carbunaru
*
* @throws Exception If it fails.
*/
@Test
public void testLockFailedExceptionHandler() throws Exception {
String localTestRepository = "target/test-resources/local";
String remoteTestRepository = "target/test-resources/remote";
Repository remoteRepo = createRepository(remoteTestRepository);
// Commit to remote
GitAccess gitAccess = GitAccess.getInstance();
gitAccess.setRepositorySynchronously(remoteTestRepository);
try (PrintWriter out = new PrintWriter(remoteTestRepository + "/" + "cucu.txt")) {
out.println("");
}
gitAccess.add(new FileStatus(GitChangeType.ADD, "cucu.txt"));
gitAccess.commit("New file: " + "cucu.txt");
// Create local repo and bind it to remote
Repository localRepo = createRepository(localTestRepository);
bindLocalToRemote(localRepo, remoteRepo);
// Create index.lock file in the local repository
gitAccess.setRepositorySynchronously(localTestRepository);
File indexFile = new File(localTestRepository, ".git/index.lock");
indexFile.createNewFile();
List<String> errorMessages = new ArrayList<>();
List<Throwable> exceptions = new ArrayList<>();
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
errorMessages.add((String) invocation.getArguments()[0]);
exceptions.add((Throwable) invocation.getArguments()[1]);
return null;
}
}).when(PluginWorkspaceProvider.getPluginWorkspace()).showErrorMessage(Mockito.any(), Mockito.any());
// Try to pull
GitController gitController = new GitController();
Future<?> pull = gitController.pull(PullType.MERGE_FF);
pull.get();
// Verify an exception was intercepted
assertFalse(exceptions.isEmpty());
assertNotNull("The exception wan't intercepted.", exceptions.get(0));
// Verify the error message to contain the information of an LockFailedException
assertFalse(errorMessages.isEmpty());
assertTrue(errorMessages.get(0).contains("Cannot lock"));
assertTrue(errorMessages.get(0).contains("Ensure that no other process has an open file handle on the lock file"));
assertTrue(errorMessages.get(0).contains("then you may delete the lock file and retry."));
// See if the exception is an instance of LockFailedException
assertEquals(LockFailedException.class.getName(), exceptions.get(0).getClass().getName());
}
Aggregations