use of com.oxygenxml.git.service.GitControllerBase in project oxygen-git-client-addon by oxygenxml.
the class BranchActionsTest method testCheckoutLocalBranchAction.
/**
* Tests the action of checkout of a local branch.
*
* @throws Exception
*/
public void testCheckoutLocalBranchAction() throws Exception {
File file = new File(LOCAL_TEST_REPOSITORY + "local.txt");
file.createNewFile();
setFileContent(file, "local content");
// Make the first commit for the local repository and create a branch for it.
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("First local commit.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
gitAccess.createBranch(LOCAL_BRANCH_NAME2);
gitAccess.fetch();
String initialBranchName = gitAccess.getBranchInfo().getBranchName();
assertEquals(GitAccess.DEFAULT_BRANCH_NAME, initialBranchName);
GitControllerBase mock = new GitController();
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
// ------------- Checkout the first branch in the tree: LOCAL_BRANCH_NAME1 -------------
GitTreeNode firstLeaf = (GitTreeNode) root.getFirstLeaf();
String firstLeafPath = (String) firstLeaf.getUserObject();
assertTrue(firstLeafPath.contains(Constants.R_HEADS));
String[] branchPath = firstLeafPath.split("/");
assertEquals(LOCAL_BRANCH_NAME1, branchPath[branchPath.length - 1]);
List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
for (AbstractAction abstractAction : actionsForNode) {
if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.CHECKOUT))) {
abstractAction.actionPerformed(null);
break;
}
}
sleep(500);
gitAccess.fetch();
assertEquals(LOCAL_BRANCH_NAME1, gitAccess.getRepository().getBranch());
// ------------- Checkout the next branch in the tree: LOCAL_BRANCH_NAME1 -------------
GitTreeNode nextLeaf = (GitTreeNode) firstLeaf.getNextLeaf();
String nextLeafPath = (String) nextLeaf.getUserObject();
assertTrue(nextLeafPath.contains(Constants.R_HEADS));
branchPath = nextLeafPath.split("/");
assertEquals(LOCAL_BRANCH_NAME2, branchPath[branchPath.length - 1]);
AbstractAction checkoutAction = branchTreeMenuActionsProvider.getCheckoutAction(nextLeaf);
if (checkoutAction != null) {
checkoutAction.actionPerformed(null);
}
sleep(500);
gitAccess.fetch();
assertEquals(LOCAL_BRANCH_NAME2, gitAccess.getRepository().getBranch());
}
use of com.oxygenxml.git.service.GitControllerBase in project oxygen-git-client-addon by oxygenxml.
the class BranchMergingTest method testBranchMergingWithoutResolvingConflict.
/**
*<p><b>Description:</b>Tests the merging after you have an ignored conflict.</p>
* <p><b>Bug ID:</b> EXM-43410</p>
*
* @author gabriel_nedianu
*
* @throws Exception
*/
public void testBranchMergingWithoutResolvingConflict() throws Exception {
JDialog conflictMergeDialog = null;
JDialog mergeOkDialog = null;
File file = new File(LOCAL_TEST_REPOSITORY, "local.txt");
file.createNewFile();
setFileContent(file, "local file 1 content");
// Make the first commit for the local repository and create a new branch
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("1st commit on main.");
gitAccess.createBranch(LOCAL_BRANCH_NAME1);
GitControllerBase mock = new GitController(GitAccess.getInstance());
BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
branchManagementPanel.refreshBranches();
flushAWT();
// ------------- Checkout branch: LOCAL_BRANCH_NAME1 -------------
gitAccess.setBranch(LOCAL_BRANCH_NAME1);
// Commit on this branch
setFileContent(file, "local file ... new branch");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("Commit on secondary branch");
// ------------- Move to the main branch and commit something there ---------------
gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
setFileContent(file, "file modifications");
gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
gitAccess.commit("2nd commit on main");
// Merge secondary branch into main
BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
GitTreeNode secondaryBranchNode = (GitTreeNode) root.getFirstLeaf();
String secondaryBranchPath = (String) secondaryBranchNode.getUserObject();
assertTrue(secondaryBranchPath.contains(Constants.R_HEADS));
List<AbstractAction> actionsForSecondaryBranch = branchTreeMenuActionsProvider.getActionsForNode(secondaryBranchNode);
for (AbstractAction action : actionsForSecondaryBranch) {
if (action != null) {
String actionName = action.getValue(AbstractAction.NAME).toString();
if ("Merge_Branch1_Into_Branch2".equals(actionName)) {
SwingUtilities.invokeLater(() -> action.actionPerformed(null));
break;
}
}
}
flushAWT();
sleep(300);
// Confirm merge dialog
mergeOkDialog = findDialog(translator.getTranslation(Tags.MERGE_BRANCHES));
JButton mergeOkButton = findFirstButton(mergeOkDialog, translator.getTranslation(Tags.MERGE));
mergeOkButton.doClick();
sleep(200);
conflictMergeDialog = findDialog(translator.getTranslation(Tags.MERGE_CONFLICTS_TITLE));
assertNotNull(conflictMergeDialog);
conflictMergeDialog.dispose();
sleep(200);
// Don't resolve merge conflicts and try to do the merge again and we will get an errMsg
// Mock showErrorMessage
StandalonePluginWorkspace pluginWSMock = Mockito.mock(StandalonePluginWorkspace.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
String message = (String) invocation.getArguments()[0];
errMsg[0] = message;
return null;
}
}).when(pluginWSMock).showErrorMessage(Mockito.anyString());
PluginWorkspaceProvider.setPluginWorkspace(pluginWSMock);
List<AbstractAction> actionsForSecondaryBranch2 = branchTreeMenuActionsProvider.getActionsForNode(secondaryBranchNode);
for (AbstractAction action : actionsForSecondaryBranch2) {
if (action != null) {
String actionName = action.getValue(AbstractAction.NAME).toString();
if ("Merge_Branch1_Into_Branch2".equals(actionName)) {
SwingUtilities.invokeLater(() -> action.actionPerformed(null));
break;
}
}
}
flushAWT();
sleep(200);
assertEquals("Resolve_conflicts_first", errMsg[0]);
}
use of com.oxygenxml.git.service.GitControllerBase 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()));
}
Aggregations