Search in sources :

Example 16 with GitControllerBase

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());
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) AbstractAction(javax.swing.AbstractAction)

Example 17 with GitControllerBase

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]);
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) File(java.io.File) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 18 with GitControllerBase

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()));
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) MergeBranchesDialog(com.oxygenxml.git.view.dialog.MergeBranchesDialog) File(java.io.File) AbstractAction(javax.swing.AbstractAction)

Aggregations

GitControllerBase (com.oxygenxml.git.service.GitControllerBase)18 FileStatus (com.oxygenxml.git.service.entities.FileStatus)17 File (java.io.File)17 GitController (com.oxygenxml.git.view.event.GitController)13 JButton (javax.swing.JButton)12 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)11 AbstractAction (javax.swing.AbstractAction)11 JDialog (javax.swing.JDialog)9 Repository (org.eclipse.jgit.lib.Repository)6 Test (org.junit.Test)6 PullResponse (com.oxygenxml.git.service.PullResponse)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 GitAccess (com.oxygenxml.git.service.GitAccess)3 ConflictButtonsPanel (com.oxygenxml.git.view.staging.ConflictButtonsPanel)3 JTextField (javax.swing.JTextField)3 ConflictResolution (com.oxygenxml.git.service.ConflictResolution)2 Translator (com.oxygenxml.git.translator.Translator)2 URL (java.net.URL)2 JCheckBox (javax.swing.JCheckBox)2 StandalonePluginWorkspace (ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)2