use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class BranchMergingTest method testBranchSquashMerging.
/**
* <p><b>Description:</b>Tests the branch squash and merge.</p>
* <p><b>Bug ID:</b> EXM-49976</p>
*
* @author alex_smarandache
*
* @throws Exception
*/
public void testBranchSquashMerging() throws Exception {
final File file = new File(LOCAL_TEST_REPOSITORY, "local.txt");
file.createNewFile();
setFileContent(file, "local content");
final String initialBranchName = gitAccess.getBranchInfo().getBranchName();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, initialBranchName);
// Make the first commit for the local repository on the main branch
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
// ------------- Checkout the other branch in the tree: LOCAL_BRANCH_NAME1 -------------
GitControllerBase mock = new GitController();
final BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
refreshSupport.call();
final GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
final GitTreeNode firstLeaf = (GitTreeNode) root.getFirstLeaf();
final String firstLeafPath = (String) firstLeaf.getUserObject();
assertTrue(firstLeafPath.contains(Constants.R_HEADS));
String[] branchPath = firstLeafPath.split("/");
assertEquals(LOCAL_BRANCH_NAME1, branchPath[branchPath.length - 1]);
refreshSupport.call();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
for (AbstractAction abstractAction : actionsForNode) {
if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.CHECKOUT))) {
abstractAction.actionPerformed(null);
break;
}
}
refreshSupport.call();
flushAWT();
sleep(300);
assertEquals(LOCAL_BRANCH_NAME1, gitAccess.getRepository().getBranch());
// Change file on the secondary branch
setFileContent(file, "local content for merging");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("Branch commit");
refreshSupport.call();
final File file2 = new File(LOCAL_TEST_REPOSITORY, "local2.txt");
file2.createNewFile();
setFileContent(file2, "squash content");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
gitAccess.commit("Branch commit 2");
refreshSupport.call();
// Move back to the main branch
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getBranchInfo().getBranchName());
refreshSupport.call();
// Merge LocalBranch into main
final List<AbstractAction> actionsForSecondaryBranch = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
for (AbstractAction action : actionsForSecondaryBranch) {
if (action != null) {
String actionName = action.getValue(AbstractAction.NAME).toString();
if ("Merge_Branch1_Into_Branch2".equals(actionName)) {
action.actionPerformed(null);
break;
}
}
}
flushAWT();
sleep(300);
// Confirm merge dialog
final MergeBranchesDialog mergeBranchesDialog = (MergeBranchesDialog) findDialog(translator.getTranslation(Tags.MERGE_BRANCHES));
mergeBranchesDialog.getSquashOption().setSelected(true);
JButton mergeOkButton = findFirstButton(mergeBranchesDialog, translator.getTranslation(Tags.MERGE));
mergeOkButton.doClick();
sleep(200);
final List<CommitCharacteristics> commits = GitAccess.getInstance().getCommitsCharacteristics(HistoryStrategy.CURRENT_LOCAL_BRANCH, null, null);
assertEquals(2, commits.size());
for (CommitCharacteristics commit : commits) {
// test if every commit has maximum one parent.
assertTrue(commit.getPlotCommit().getParentCount() < 2);
}
assertEquals("local content for merging", TestUtil.read(file.toURI().toURL()));
assertEquals("squash content", TestUtil.read(file2.toURI().toURL()));
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitAccessConflictTest method testPullWithConflicts_Rebase_ResolveUsingTheirs_Continue.
/**
* Pull (rebase).
*
* @throws Exception
*/
@Test
public void testPullWithConflicts_Rebase_ResolveUsingTheirs_Continue() throws Exception {
// ----------------
// LOCAL 1
// ----------------
gitAccess = GitAccess.getInstance();
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
// Create a file in the remote.
File remoteParent = new File(FIRST_LOCAL_TEST_REPOSITPRY);
remoteParent.mkdirs();
File local1File = new File(FIRST_LOCAL_TEST_REPOSITPRY, "test.txt");
writeToFile(local1File, "original");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("Primul");
push("", "");
// ----------------
// LOCAL 2
// ----------------
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
PullResponse pull = pull("", "", PullType.MERGE_FF, false);
assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
File local2File = new File(SECOND_LOCAL_TEST_REPOSITORY, "test.txt");
assertEquals("original", getFileContent(local2File));
writeToFile(local2File, "changed in local 2");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("Al doilea");
push("", "");
// ----------------
// LOCAL 1
// ----------------
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
writeToFile(local1File, "changed in local 1");
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
assertEquals("changed in local 1", getFileContent(local1File));
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("Another");
pc.pull(PullType.REBASE).get();
assertNull(pullFailedMessage[0]);
assertFalse(wasRebaseInterrupted[0]);
assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullWithConflictsSB.toString());
assertTrue(getFileContent(local1File).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
// Show the "Interrupted rebase" dialog
pc.pull(PullType.REBASE).get();
assertTrue(wasRebaseInterrupted[0]);
Status status = gitAccess.getGit().status().call();
assertEquals("[test.txt]", status.getConflicting().toString());
assertTrue(getFileContent(local1File).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
GitControllerBase gitCtrl = new GitControllerBase(gitAccess) {
@Override
protected boolean isUserOKWithResolvingRebaseConflictUsingMineOrTheirs(ConflictResolution cmd) {
return cmd == ConflictResolution.RESOLVE_USING_THEIRS;
}
};
gitCtrl.asyncResolveUsingTheirs(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
sleep(700);
// When having a conflict while rebasing, 'Mine' and 'Theirs' become reversed
assertEquals("When having a conflict while rebasing, 'Mine' and 'Theirs' become reversed ", "changed in local 1", getFileContent(local1File));
GitStatus gitStatus = gitAccess.getStatus();
assertEquals(1, gitStatus.getStagedFiles().size());
assertEquals("(changeType=CHANGED, fileLocation=test.txt)", gitStatus.getStagedFiles().get(0).toString());
assertTrue(gitStatus.getUnstagedFiles().isEmpty());
RepositoryState repositoryState = gitAccess.getRepository().getRepositoryState();
assertEquals(RepositoryState.REBASING_MERGE, repositoryState);
gitAccess.continueRebase();
sleep(700);
repositoryState = gitAccess.getRepository().getRepositoryState();
assertEquals(RepositoryState.SAFE, repositoryState);
gitStatus = gitAccess.getStatus();
assertTrue(gitStatus.getStagedFiles().isEmpty());
assertTrue(gitStatus.getUnstagedFiles().isEmpty());
assertEquals(0, gitAccess.getPullsBehind());
assertEquals(1, gitAccess.getPushesAhead());
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitAccessConflictTest method testResolveUsingTheirs.
@Test
public void testResolveUsingTheirs() throws Exception {
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
OptionsManager.getInstance().saveSelectedRepository(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("", "");
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
OptionsManager.getInstance().saveSelectedRepository(SECOND_LOCAL_TEST_REPOSITORY);
File testFileSecondRepo = new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
testFileSecondRepo.createNewFile();
writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "teeeeeest");
FileStatus fileStatus = new FileStatus(GitChangeType.ADD, "test.txt");
gitAccess.add(fileStatus);
gitAccess.commit("conflict");
pull("", "", PullType.MERGE_FF, false);
GitController gitCtrl = new GitController(gitAccess);
gitCtrl.asyncResolveUsingTheirs(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
sleep(700);
String expected = "hellllo";
String actual = getFileContent(testFileSecondRepo);
assertEquals(expected, actual);
// Pulling now will say that the merge was not concluded and we should commit
assertEquals(RepositoryState.MERGING_RESOLVED, gitAccess.getRepository().getRepositoryState());
GitController ppc = new GitController(gitAccess);
ppc.pull();
sleep(1200);
assertEquals("Conclude_Merge_Message", shownWarningMess[0]);
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitAccessConflictTest method testPullWithConflicts_Rebase_ResolveUsingMine_Abort.
/**
* Pull (rebase) with conflict. Resolve using theirs and then abort.
*
* @throws Exception
*/
@Test
public void testPullWithConflicts_Rebase_ResolveUsingMine_Abort() throws Exception {
// ----------------
// LOCAL 1
// ----------------
gitAccess = GitAccess.getInstance();
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
// Create a file in the remote.
File remoteParent = new File(FIRST_LOCAL_TEST_REPOSITPRY);
remoteParent.mkdirs();
File local1File = new File(FIRST_LOCAL_TEST_REPOSITPRY, "test.txt");
writeToFile(local1File, "original");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("Primul");
push("", "");
// ----------------
// LOCAL 2
// ----------------
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
PullResponse pull = pull("", "", PullType.MERGE_FF, false);
assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
File local2File = new File(SECOND_LOCAL_TEST_REPOSITORY, "test.txt");
assertEquals("original", getFileContent(local2File));
writeToFile(local2File, "changed in local 2");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("Al doilea");
push("", "");
// ----------------
// LOCAL 1
// ----------------
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
writeToFile(local1File, "changed in local 1");
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
assertEquals("changed in local 1", getFileContent(local1File));
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("Another");
pc.pull(PullType.REBASE).get();
assertNull(pullFailedMessage[0]);
assertFalse(wasRebaseInterrupted[0]);
assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullWithConflictsSB.toString());
assertTrue(getFileContent(local1File).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
// Show the "Interrupted rebase" dialog
pc.pull(PullType.REBASE).get();
assertTrue(wasRebaseInterrupted[0]);
Status status = gitAccess.getGit().status().call();
assertEquals("[test.txt]", status.getConflicting().toString());
assertTrue(getFileContent(local1File).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
GitControllerBase gitCtrl = new GitControllerBase(gitAccess) {
@Override
protected boolean isUserOKWithResolvingRebaseConflictUsingMineOrTheirs(ConflictResolution cmd) {
return cmd == ConflictResolution.RESOLVE_USING_MINE;
}
};
gitCtrl.asyncResolveUsingMine(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
sleep(700);
// When having a conflict while rebasing, 'Mine' and 'Theirs' become reversed
assertEquals("When having a conflict while rebasing, 'Mine' and 'Theirs' become reversed ", "changed in local 2", getFileContent(local1File));
GitStatus gitStatus = gitAccess.getStatus();
assertTrue(gitStatus.getStagedFiles().isEmpty());
assertTrue(gitStatus.getUnstagedFiles().isEmpty());
RepositoryState repositoryState = gitAccess.getRepository().getRepositoryState();
assertEquals(RepositoryState.REBASING_MERGE, repositoryState);
// Abort. Go back to the state before trying to pull.
gitAccess.abortRebase();
sleep(700);
repositoryState = gitAccess.getRepository().getRepositoryState();
assertEquals(RepositoryState.SAFE, repositoryState);
assertEquals("changed in local 1", getFileContent(local1File));
// The counters are back to the state from before pull
assertEquals(1, gitAccess.getPullsBehind());
assertEquals(1, gitAccess.getPushesAhead());
}
use of com.oxygenxml.git.view.event.GitController in project oxygen-git-client-addon by oxygenxml.
the class GitAccessConflictTest method testPullWithConflicts_Rebase_ResolveUsingTheirs_Abort.
/**
* Pull (rebase).
*
* @throws Exception
*/
@Test
public void testPullWithConflicts_Rebase_ResolveUsingTheirs_Abort() throws Exception {
// ----------------
// LOCAL 1
// ----------------
gitAccess = GitAccess.getInstance();
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
// Create a file in the remote.
File remoteParent = new File(FIRST_LOCAL_TEST_REPOSITPRY);
remoteParent.mkdirs();
File local1File = new File(FIRST_LOCAL_TEST_REPOSITPRY, "test.txt");
writeToFile(local1File, "original");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("Primul");
push("", "");
// ----------------
// LOCAL 2
// ----------------
gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
PullResponse pull = pull("", "", PullType.MERGE_FF, false);
assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
File local2File = new File(SECOND_LOCAL_TEST_REPOSITORY, "test.txt");
assertEquals("original", getFileContent(local2File));
writeToFile(local2File, "changed in local 2");
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("Al doilea");
push("", "");
// ----------------
// LOCAL 1
// ----------------
gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
writeToFile(local1File, "changed in local 1");
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
assertEquals("changed in local 1", getFileContent(local1File));
gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
gitAccess.commit("Another");
pc.pull(PullType.REBASE).get();
assertNull(pullFailedMessage[0]);
assertFalse(wasRebaseInterrupted[0]);
assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullWithConflictsSB.toString());
assertTrue(getFileContent(local1File).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
// Show the "Interrupted rebase" dialog
pc.pull(PullType.REBASE).get();
assertTrue(wasRebaseInterrupted[0]);
Status status = gitAccess.getGit().status().call();
assertEquals("[test.txt]", status.getConflicting().toString());
assertTrue(getFileContent(local1File).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
GitControllerBase gitCtrl = new GitControllerBase(gitAccess) {
@Override
protected boolean isUserOKWithResolvingRebaseConflictUsingMineOrTheirs(ConflictResolution cmd) {
return cmd == ConflictResolution.RESOLVE_USING_THEIRS;
}
};
gitCtrl.asyncResolveUsingTheirs(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
sleep(700);
// When having a conflict while rebasing, 'Mine' and 'Theirs' become reversed
assertEquals("When having a conflict while rebasing, 'Mine' and 'Theirs' become reversed ", "changed in local 1", getFileContent(local1File));
GitStatus gitStatus = gitAccess.getStatus();
assertEquals(1, gitStatus.getStagedFiles().size());
assertEquals("(changeType=CHANGED, fileLocation=test.txt)", gitStatus.getStagedFiles().get(0).toString());
assertTrue(gitStatus.getUnstagedFiles().isEmpty());
RepositoryState repositoryState = gitAccess.getRepository().getRepositoryState();
assertEquals(RepositoryState.REBASING_MERGE, repositoryState);
gitAccess.abortRebase();
sleep(700);
repositoryState = gitAccess.getRepository().getRepositoryState();
assertEquals(RepositoryState.SAFE, repositoryState);
gitStatus = gitAccess.getStatus();
assertTrue(gitStatus.getStagedFiles().isEmpty());
assertTrue(gitStatus.getUnstagedFiles().isEmpty());
// Back before pull
assertEquals(1, gitAccess.getPullsBehind());
assertEquals(1, gitAccess.getPushesAhead());
}
Aggregations