use of com.oxygenxml.git.view.dialog.MergeBranchesDialog in project oxygen-git-client-addon by oxygenxml.
the class BranchTreeMenuActionsProvider method createMergeAction.
/**
* Create merge action for [selected_branch] into [current_branch].
*
* @param nodePath The node path of the selected branch.
*
* @return The merge action.
*/
private AbstractAction createMergeAction(String nodePath) {
String selectedBranch = BranchesUtil.createBranchPath(nodePath, BranchManagementConstants.LOCAL_BRANCH_NODE_TREE_LEVEL);
String currentBranch = GitAccess.getInstance().getBranchInfo().getBranchName();
String mergeActionName = MessageFormat.format(Translator.getInstance().getTranslation(Tags.MERGE_BRANCH1_INTO_BRANCH2), TextFormatUtil.shortenText(selectedBranch, UIConstants.BRANCH_NAME_MAXIMUM_LENGTH, 0, "..."), TextFormatUtil.shortenText(currentBranch, UIConstants.BRANCH_NAME_MAXIMUM_LENGTH, 0, "...")) + "...";
return new AbstractAction(mergeActionName) {
@Override
public void actionPerformed(ActionEvent e) {
ctrl.asyncTask(() -> {
if (RepoUtil.isUnfinishedConflictState(ctrl.getGitAccess().getRepository().getRepositoryState())) {
PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(TRANSLATOR.getTranslation(Tags.RESOLVE_CONFLICTS_FIRST));
} else {
final MergeBranchesDialog mergeDialog = new MergeBranchesDialog(currentBranch, selectedBranch);
if (mergeDialog.getResult() == OKCancelDialog.RESULT_OK) {
if (mergeDialog.isSquashSelected()) {
ctrl.getGitAccess().squashAndMergeBranch(nodePath);
} else {
ctrl.getGitAccess().mergeBranch(nodePath);
}
}
}
return null;
}, ex -> PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage(ex.getMessage(), ex));
}
};
}
use of com.oxygenxml.git.view.dialog.MergeBranchesDialog 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