use of com.oxygenxml.git.service.PullResponse in project oxygen-git-client-addon by oxygenxml.
the class DiffPresenterTest method testRebasingFileDiff.
@Test
public void testRebasingFileDiff() throws Exception {
// The local repositories.
String localTestRepository1 = "target/test-resources/local1";
String localTestRepository2 = "target/test-resources/local2";
// The remote repository.
String remoteTestRepository = "target/test-resources/remote";
GitAccess gitAccess = GitAccess.getInstance();
Repository remoteRepo = createRepository(remoteTestRepository);
Repository localRepo1 = createRepository(localTestRepository1);
Repository localRepo2 = createRepository(localTestRepository2);
// -------------
// Set up the repositories for a rebase conflict
// -------------
// ----------------
// LOCAL 1
// ----------------
// Bind the local repository 1 to the remote one.
bindLocalToRemote(localRepo1, remoteRepo);
gitAccess.setRepositorySynchronously(localTestRepository1);
// Create a new file for the first repository.
File localFile1 = new File(localTestRepository1 + "/test.txt");
localFile1.createNewFile();
// Modify the newly created file.
setFileContent(localFile1, "initial content");
// Add it to the index.
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("First commit.");
// Send it to remote/upstream.
push("", "");
// ----------------
// LOCAL 2
// ----------------
// Bind the local repository 2 to the remote one.
bindLocalToRemote(localRepo2, remoteRepo);
gitAccess.setRepositorySynchronously(localTestRepository2);
// Receive changes from remote/upstream.
PullResponse pull = pull("", "", PullType.MERGE_FF, false);
assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
// Create new file for second repository.
File local2File = new File(localTestRepository2, "test.txt");
assertEquals("initial content", TestUtil.read(local2File.toURI().toURL()));
// Modify the file.
setFileContent(local2File, "changed in local 2, resolved");
// Add it to the index.
gitAccess.add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
gitAccess.commit("Second commit");
// Send it to remote/upstream.
push("", "");
// ----------------
// LOCAL 1
// ----------------
gitAccess.setRepositorySynchronously(localTestRepository1);
// Modify the file.
setFileContent(localFile1, "changed in local 1, conflict content, original");
// Add it to the index.
gitAccess.add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
// Commit the file.
gitAccess.commit("Third commit, with conflict");
// ------------
// Rebase conflict prepared and will happen after the pull.
// ------------
final StringBuilder pullWithConflictsSB = new StringBuilder();
boolean[] wasRebaseInterrupted = new boolean[1];
final String[] pullFailedMessage = new String[1];
GitController pc = new GitController(gitAccess) {
@Override
protected void showPullFailedBecauseOfCertainChanges(List<String> changes, String message) {
pullFailedMessage[0] = message;
}
@Override
protected void showPullSuccessfulWithConflicts(PullResponse response) {
pullWithConflictsSB.append(response);
}
@Override
protected void showRebaseInProgressDialog() {
wasRebaseInterrupted[0] = true;
}
};
final StringBuilder b = new StringBuilder();
TestUtil.collectPushPullEvents(pc, b);
// Get conflict
pc.pull(PullType.REBASE).get();
assertNull(pullFailedMessage[0]);
assertFalse(wasRebaseInterrupted[0]);
assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullWithConflictsSB.toString());
assertTrue(TestUtil.read(localFile1.toURI().toURL()).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
leftDiff = null;
rightDiff = null;
// Mock the GitController
GitControllerBase gitCtrl = Mockito.mock(GitControllerBase.class);
FileStatus fileStatus = new FileStatus(GitChangeType.CONFLICT, "test.txt");
// Invoke DIFF over the changed file.
DiffPresenter.showDiff(fileStatus, gitCtrl);
assertNotNull(leftDiff);
assertNotNull(rightDiff);
// Verify that each side has the proper tag and content.
assertTrue(leftDiff.toString().contains("MineResolved"));
assertTrue(rightDiff.toString().contains("MineOriginal"));
assertEquals("changed in local 2, resolved", TestUtil.read(leftDiff));
assertEquals("changed in local 1, conflict content, original", TestUtil.read(rightDiff));
}
use of com.oxygenxml.git.service.PullResponse in project oxygen-git-client-addon by oxygenxml.
the class FlatView10Test method testAbortMergeButton.
/**
* <p><b>Description:</b> show/hide/click "Abort merge" button.</p>
* <p><b>Bug ID:</b> EXM-46222</p>
*
* @author sorin_carbunaru
*
* @throws Exception If it fails.
*/
@Test
public void testAbortMergeButton() throws Exception {
String localTestRepository_1 = "target/test-resources/testShowHideAbortMergeButton-local-1";
String localTestRepository_2 = "target/test-resources/testShowHideAbortMergeButton-local-2";
String remoteTestRepository = "target/test-resources/testShowHideAbortMergeButton-remote";
// Create and repositories
Repository remoteRepo = createRepository(remoteTestRepository);
Repository localRepo_1 = createRepository(localTestRepository_1);
Repository localRepo_2 = createRepository(localTestRepository_2);
bindLocalToRemote(localRepo_1, remoteRepo);
bindLocalToRemote(localRepo_2, remoteRepo);
new File(localTestRepository_1).mkdirs();
new File(localTestRepository_2).mkdirs();
// -------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
File firstRepoFile = new File(localTestRepository_1 + "/test.txt");
firstRepoFile.createNewFile();
setFileContent(firstRepoFile, "First version");
GitAccess.getInstance().add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
GitAccess.getInstance().commit("First commit.");
push("", "");
// ----------------- REPO 2
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_2);
File secondRepoFile = new File(localTestRepository_2 + "/test.txt");
refreshSupport.call();
flushAWT();
sleep(400);
assertFalse(secondRepoFile.exists());
pull("", "", PullType.MERGE_FF, false);
assertTrue(secondRepoFile.exists());
// Modify file and commit and push
setFileContent(secondRepoFile, "Second versions");
GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
GitAccess.getInstance().commit("Second commit.");
push("", "");
// -------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
setFileContent(firstRepoFile, "Third version");
GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
GitAccess.getInstance().commit("Third commit.");
// Now pull to generate conflict
ConflictButtonsPanel abortMergeButtonPanel = stagingPanel.getConflictButtonsPanel();
assertFalse(abortMergeButtonPanel.isShowing());
flushAWT();
PullResponse pullResponse = pull("", "", PullType.MERGE_FF, false);
refreshSupport.call();
waitForScheduler();
assertEquals(PullStatus.CONFLICTS, pullResponse.getStatus());
RepositoryState repositoryState = GitAccess.getInstance().getRepository().getRepositoryState();
assertEquals(RepositoryState.MERGING, repositoryState);
assertTrue(abortMergeButtonPanel.isShowing());
// --------------- REPO 2
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_2);
sleep(300);
assertFalse(abortMergeButtonPanel.isShowing());
// --------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
sleep(300);
assertTrue(abortMergeButtonPanel.isShowing());
JButton abortMergeBtn = findFirstButton(abortMergeButtonPanel, Tags.ABORT_MERGE);
assertNotNull(abortMergeBtn);
// Resolve using mine
GitControllerBase gitCtrl = stagingPanel.getGitController();
PluginWorkspace spy = Mockito.spy(PluginWorkspaceProvider.getPluginWorkspace());
Mockito.when(spy.showConfirmDialog(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any())).thenReturn(0);
PluginWorkspaceProvider.setPluginWorkspace(spy);
FileStatus testFileStatus = new FileStatus(GitChangeType.CONFLICT, "test.txt");
gitCtrl.asyncResolveUsingMine(Arrays.asList(testFileStatus));
refreshSupport.call();
waitForScheduler();
flushAWT();
abortMergeButtonPanel = stagingPanel.getConflictButtonsPanel();
assertFalse(abortMergeButtonPanel.isShowing());
// Restart merge
GitAccess.getInstance().restartMerge();
flushAWT();
sleep(200);
abortMergeButtonPanel = stagingPanel.getConflictButtonsPanel();
assertTrue(abortMergeButtonPanel.isShowing());
abortMergeBtn = findFirstButton(abortMergeButtonPanel, Tags.ABORT_MERGE);
assertNotNull(abortMergeBtn);
// Resolve using theirs
gitCtrl.asyncResolveUsingTheirs(Arrays.asList(testFileStatus));
waitForScheduler();
flushAWT();
abortMergeButtonPanel = stagingPanel.getConflictButtonsPanel();
assertFalse(abortMergeButtonPanel.isShowing());
// Restart merge
GitAccess.getInstance().restartMerge();
flushAWT();
abortMergeButtonPanel = stagingPanel.getConflictButtonsPanel();
assertTrue(abortMergeButtonPanel.isShowing());
abortMergeBtn = findFirstButton(abortMergeButtonPanel, Tags.ABORT_MERGE);
assertNotNull(abortMergeBtn);
repositoryState = GitAccess.getInstance().getRepository().getRepositoryState();
assertEquals(RepositoryState.MERGING, repositoryState);
assertEquals(1, GitAccess.getInstance().getPullsBehind());
assertEquals(1, GitAccess.getInstance().getPushesAhead());
// Abort merge
abortMergeBtn.doClick();
flushAWT();
abortMergeButtonPanel = stagingPanel.getConflictButtonsPanel();
assertFalse(abortMergeButtonPanel.isShowing());
repositoryState = GitAccess.getInstance().getRepository().getRepositoryState();
assertEquals(RepositoryState.SAFE, repositoryState);
assertEquals(1, GitAccess.getInstance().getPullsBehind());
assertEquals(1, GitAccess.getInstance().getPushesAhead());
}
use of com.oxygenxml.git.service.PullResponse in project oxygen-git-client-addon by oxygenxml.
the class FlatView2Test method testShowRebasePanel_thenAbort.
/**
* <p><b>Description:</b> Show and hide (by aborting the rebase) the rebase panel.</p>
* <p><b>Bug ID:</b> EXM-42025</p>
*
* @author sorin_carbunaru
*
* @throws Exception If it fails.
*/
@Test
public void testShowRebasePanel_thenAbort() throws Exception {
String localTestRepository_1 = "target/test-resources/testShowRebasePanel_thenAbort-local-1";
String localTestRepository_2 = "target/test-resources/testShowRebasePanel_thenAbort-local-2";
String remoteTestRepository = "target/test-resources/testShowRebasePanel_thenAbort-remote";
// Create and repositories
Repository remoteRepo = createRepository(remoteTestRepository);
Repository localRepo_1 = createRepository(localTestRepository_1);
Repository localRepo_2 = createRepository(localTestRepository_2);
bindLocalToRemote(localRepo_1, remoteRepo);
bindLocalToRemote(localRepo_2, remoteRepo);
new File(localTestRepository_1).mkdirs();
new File(localTestRepository_2).mkdirs();
// -------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
File firstRepoFile = new File(localTestRepository_1 + "/test.txt");
firstRepoFile.createNewFile();
setFileContent(firstRepoFile, "First version");
GitAccess.getInstance().add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
GitAccess.getInstance().commit("First commit.");
push("", "");
// ----------------- REPO 2
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_2);
File secondRepoFile = new File(localTestRepository_2 + "/test.txt");
refreshSupport.call();
flushAWT();
sleep(400);
assertFalse(secondRepoFile.exists());
pull("", "", PullType.REBASE, false);
assertTrue(secondRepoFile.exists());
// Modify file and commit and push
setFileContent(secondRepoFile, "Second versions");
GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
GitAccess.getInstance().commit("Second commit.");
push("", "");
// -------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
setFileContent(firstRepoFile, "Third version");
GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
GitAccess.getInstance().commit("Third commit.");
// Now pull to generate conflict
ConflictButtonsPanel rebasePanel = stagingPanel.getConflictButtonsPanel();
assertFalse(rebasePanel.isShowing());
flushAWT();
PullResponse pullResponse = pull("", "", PullType.REBASE, false);
refreshSupport.call();
waitForScheduler();
sleep(1000);
assertEquals(PullStatus.CONFLICTS, pullResponse.getStatus());
assertTrue(rebasePanel.isShowing());
JButton abortButton = findFirstButton(rebasePanel, "Abort_rebase");
assertNotNull(abortButton);
abortButton.doClick();
flushAWT();
sleep(500);
assertFalse(rebasePanel.isShowing());
}
use of com.oxygenxml.git.service.PullResponse in project oxygen-git-client-addon by oxygenxml.
the class FlatView2Test method testShowHideRebasePanelWhenChangingRepo.
/**
* <p><b>Description:</b> Show and hide the rebase panel when changing the repository.</p>
* <p><b>Bug ID:</b> EXM-42025</p>
*
* @author sorin_carbunaru
*
* @throws Exception If it fails.
*/
@Test
public void testShowHideRebasePanelWhenChangingRepo() throws Exception {
String localTestRepository_1 = "target/test-resources/testShowRebasePanel_thenAbort-local-1";
String localTestRepository_2 = "target/test-resources/testShowRebasePanel_thenAbort-local-2";
String remoteTestRepository = "target/test-resources/testShowRebasePanel_thenAbort-remote";
// Create and repositories
Repository remoteRepo = createRepository(remoteTestRepository);
Repository localRepo_1 = createRepository(localTestRepository_1);
Repository localRepo_2 = createRepository(localTestRepository_2);
bindLocalToRemote(localRepo_1, remoteRepo);
bindLocalToRemote(localRepo_2, remoteRepo);
new File(localTestRepository_1).mkdirs();
new File(localTestRepository_2).mkdirs();
// -------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
File firstRepoFile = new File(localTestRepository_1 + "/test.txt");
firstRepoFile.createNewFile();
setFileContent(firstRepoFile, "First version");
GitAccess.getInstance().add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
GitAccess.getInstance().commit("First commit.");
push("", "");
// ----------------- REPO 2
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_2);
File secondRepoFile = new File(localTestRepository_2 + "/test.txt");
refreshSupport.call();
flushAWT();
sleep(400);
assertFalse(secondRepoFile.exists());
pull("", "", PullType.REBASE, false);
assertTrue(secondRepoFile.exists());
// Modify file and commit and push
setFileContent(secondRepoFile, "Second versions");
GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
GitAccess.getInstance().commit("Second commit.");
push("", "");
// -------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
setFileContent(firstRepoFile, "Third version");
GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
GitAccess.getInstance().commit("Third commit.");
// Now pull to generate conflict
ConflictButtonsPanel rebasePanel = stagingPanel.getConflictButtonsPanel();
assertFalse(rebasePanel.isShowing());
flushAWT();
PullResponse pullResponse = pull("", "", PullType.REBASE, false);
refreshSupport.call();
waitForScheduler();
assertEquals(PullStatus.CONFLICTS, pullResponse.getStatus());
assertTrue(rebasePanel.isShowing());
// --------------- REPO 2
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_2);
sleep(300);
assertFalse(rebasePanel.isShowing());
// --------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
sleep(300);
assertTrue(rebasePanel.isShowing());
}
use of com.oxygenxml.git.service.PullResponse in project oxygen-git-client-addon by oxygenxml.
the class FlatView2Test method testShowRebasePanel_thenContinue.
/**
* <p><b>Description:</b> Show and hide (by continuing the rebase) the rebase panel.</p>
* <p><b>Bug ID:</b> EXM-42025</p>
*
* @author sorin_carbunaru
*
* @throws Exception If it fails.
*/
@Test
public void testShowRebasePanel_thenContinue() throws Exception {
String localTestRepository_1 = "target/test-resources/testShowRebasePanel_thenContinue-local-1";
String localTestRepository_2 = "target/test-resources/testShowRebasePanel_thenContinue-local-2";
String remoteTestRepository = "target/test-resources/testShowRebasePanel_thenContinue-remote";
// Create and repositories
Repository remoteRepo = createRepository(remoteTestRepository);
Repository localRepo_1 = createRepository(localTestRepository_1);
Repository localRepo_2 = createRepository(localTestRepository_2);
bindLocalToRemote(localRepo_1, remoteRepo);
bindLocalToRemote(localRepo_2, remoteRepo);
new File(localTestRepository_1).mkdirs();
new File(localTestRepository_2).mkdirs();
// -------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
File firstRepoFile = new File(localTestRepository_1 + "/test.txt");
firstRepoFile.createNewFile();
setFileContent(firstRepoFile, "First version");
GitAccess.getInstance().add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
GitAccess.getInstance().commit("First commit.");
push("", "");
// ----------------- REPO 2
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_2);
File secondRepoFile = new File(localTestRepository_2 + "/test.txt");
refreshSupport.call();
flushAWT();
sleep(400);
assertFalse(secondRepoFile.exists());
pull("", "", PullType.REBASE, false);
assertTrue(secondRepoFile.exists());
// Modify file and commit and push
setFileContent(secondRepoFile, "Second versions");
GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
GitAccess.getInstance().commit("Second commit.");
push("", "");
// -------------- REPO 1
GitAccess.getInstance().setRepositorySynchronously(localTestRepository_1);
setFileContent(firstRepoFile, "Third version");
GitAccess.getInstance().add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
GitAccess.getInstance().commit("Third commit.");
// Now pull to generate conflict
ConflictButtonsPanel rebasePanel = stagingPanel.getConflictButtonsPanel();
assertFalse(rebasePanel.isShowing());
flushAWT();
PullResponse pullResponse = pull("", "", PullType.REBASE, false);
refreshSupport.call();
waitForScheduler();
assertEquals(PullStatus.CONFLICTS, pullResponse.getStatus());
assertTrue(rebasePanel.isShowing());
GitControllerBase sc = new GitControllerBase(GitAccess.getInstance()) {
@Override
protected boolean isUserOKWithResolvingRebaseConflictUsingMineOrTheirs(ConflictResolution cmd) {
return cmd == ConflictResolution.RESOLVE_USING_MINE;
}
};
sc.asyncResolveUsingMine(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
waitForScheduler();
flushAWT();
JButton continueBtn = findFirstButton(rebasePanel, Tags.CONTINUE_REBASE);
assertNotNull(continueBtn);
continueBtn.doClick();
waitForScheduler();
flushAWT();
assertFalse(rebasePanel.isShowing());
}
Aggregations