Search in sources :

Example 1 with GitControllerBase

use of com.oxygenxml.git.service.GitControllerBase in project oxygen-git-client-addon by oxygenxml.

the class FlatView2Test method testShowInterruptedRebaseDlg_thenContinue.

/**
 * <p><b>Description:</b> Show interrupted rebase dialog and press continue.</p>
 * <p><b>Bug ID:</b> EXM-42025</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception If it fails.
 */
@Test
public void testShowInterruptedRebaseDlg_thenContinue() throws Exception {
    try {
        String localTestRepository_1 = "target/test-resources/testShowInterruptedRebaseDlg_thenContinue-local-1";
        String localTestRepository_2 = "target/test-resources/testShowInterruptedRebaseDlg_thenContinue-local-2";
        String remoteTestRepository = "target/test-resources/testShowInterruptedRebaseDlg_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();
        flushAWT();
        sleep(500);
        assertEquals(PullStatus.CONFLICTS, pullResponse.getStatus());
        assertTrue(rebasePanel.isShowing());
        // Pull again. Rebase in progress dialog is shown
        GitController ppc = (GitController) stagingPanel.getGitController();
        ppc.pull(PullType.REBASE);
        flushAWT();
        sleep(300);
        JDialog rebaseInProgressDlg = findDialog(Tags.REBASE_IN_PROGRESS);
        assertNotNull(rebaseInProgressDlg);
        // Get Cannot_continue_rebase_because_of_conflicts message
        final String[] errMessage = new String[1];
        StandalonePluginWorkspace mockedPluginWS = Mockito.mock(StandalonePluginWorkspace.class);
        Mockito.doAnswer(new Answer<Void>() {

            @Override
            public Void answer(InvocationOnMock invocation) throws Throwable {
                Object[] arguments = invocation.getArguments();
                if (arguments != null && arguments.length == 1) {
                    errMessage[0] = arguments[0].toString();
                }
                return null;
            }
        }).when(mockedPluginWS).showErrorMessage(Mockito.anyString());
        Mockito.when(mockedPluginWS.getParentFrame()).thenReturn(null);
        PluginWorkspaceProvider.setPluginWorkspace(mockedPluginWS);
        JButton continueBtn = findFirstButton(rebaseInProgressDlg.getRootPane(), Translator.getInstance().getTranslation(Tags.CONTINUE_REBASE));
        continueBtn.doClick();
        waitForScheduler();
        assertEquals("Cannot_continue_rebase_because_of_conflicts", errMessage[0]);
        // Resolve conflict
        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")));
        flushAWT();
        // Pull again.
        ppc.pull(PullType.REBASE);
        flushAWT();
        sleep(300);
        // Rebase in progress dialog shown
        rebaseInProgressDlg = findDialog(Tags.REBASE_IN_PROGRESS);
        assertNotNull(rebaseInProgressDlg);
        // Now CONTINUE
        continueBtn = findFirstButton(rebaseInProgressDlg.getRootPane(), Translator.getInstance().getTranslation(Tags.CONTINUE_REBASE));
        continueBtn.doClick();
        flushAWT();
        waitForScheduler();
        sleep(1000);
        rebaseInProgressDlg = findDialog(Tags.REBASE_IN_PROGRESS);
        assertNull(rebaseInProgressDlg);
        assertFalse(rebasePanel.isShowing());
        assertTableModels(// Unstaged
        "", // Staged
        "");
    } finally {
        PluginWorkspaceProvider.setPluginWorkspace(null);
    }
}
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) Repository(org.eclipse.jgit.lib.Repository) PullResponse(com.oxygenxml.git.service.PullResponse) ConflictButtonsPanel(com.oxygenxml.git.view.staging.ConflictButtonsPanel) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConflictResolution(com.oxygenxml.git.service.ConflictResolution) StandalonePluginWorkspace(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace) File(java.io.File) JDialog(javax.swing.JDialog) Test(org.junit.Test)

Example 2 with GitControllerBase

use of com.oxygenxml.git.service.GitControllerBase in project oxygen-git-client-addon by oxygenxml.

the class WorkingCopySelectorTest method testClearHistory.

/**
 * <p><b>Description:</b> test the "Clear history..." action.</p>
 * <p><b>Bug ID:</b> EXM-44205</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception When failing.
 */
public void testClearHistory() throws Exception {
    JFrame frame = new JFrame();
    try {
        GitControllerBase mock = Mockito.mock(GitControllerBase.class);
        GitAccess instance = GitAccess.getInstance();
        Mockito.when(mock.getGitAccess()).thenReturn(instance);
        WorkingCopySelectionPanel wcPanel = new WorkingCopySelectionPanel(mock, true);
        frame.getContentPane().add(wcPanel);
        frame.pack();
        // Showing the WC panel also initializes the combo
        SwingUtilities.invokeAndWait(() -> frame.setVisible(true));
        sleep(150);
        JComboBox<String> workingCopyCombo = wcPanel.getWorkingCopyCombo();
        ComboBoxModel<String> model = workingCopyCombo.getModel();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < model.getSize(); i++) {
            sb.append(model.getElementAt(i)).append("\n");
        }
        assertEquals("D:/folder/WC1\n" + "D:/folder/WC2\n" + "D:/folder_doi/WC\n" + "CLEAR_HISTORY\n", sb.toString());
        SwingUtilities.invokeAndWait(() -> workingCopyCombo.setSelectedItem("CLEAR_HISTORY"));
        sleep(150);
        sb = new StringBuilder();
        for (int i = 0; i < model.getSize(); i++) {
            sb.append(model.getElementAt(i)).append("\n");
        }
        assertEquals("D:/folder/WC1\n", sb.toString());
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) GitAccess(com.oxygenxml.git.service.GitAccess) WorkingCopySelectionPanel(com.oxygenxml.git.view.staging.WorkingCopySelectionPanel) JFrame(javax.swing.JFrame)

Example 3 with GitControllerBase

use of com.oxygenxml.git.service.GitControllerBase in project oxygen-git-client-addon by oxygenxml.

the class BranchActionsTest method testContextualMenuActionsOnCurrentBranch.

/**
 *<p><b>Description:</b>Tests the action created on the current Branch</p>
 * <p><b>Bug ID:</b> EXM-43410</p>
 *
 * @author gabriel_nedianu
 *
 * @throws Exception
 */
public void testContextualMenuActionsOnCurrentBranch() 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
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
    gitAccess.commit("First local commit.");
    // Verify we are on main branch
    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());
    GitTreeNode mainBranchNode = (GitTreeNode) root.getFirstLeaf();
    String mainBranchPath = (String) mainBranchNode.getUserObject();
    assertEquals("refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME, mainBranchPath);
    // ------------- Verify the actions on the selected branch -------------
    List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(mainBranchNode);
    int noOfActions = actionsForNode.size();
    assertEquals(1, noOfActions);
    String actionName = (String) actionsForNode.get(0).getValue(AbstractAction.NAME);
    assertEquals(translator.getTranslation(Tags.CREATE_BRANCH) + "...", actionName);
}
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 4 with GitControllerBase

use of com.oxygenxml.git.service.GitControllerBase in project oxygen-git-client-addon by oxygenxml.

the class BranchActionsTest method testCreateLocalBranchAction.

/**
 * Tests the action of creating a new branch from a local branch.
 *
 * @throws Exception
 */
public void testCreateLocalBranchAction() throws Exception {
    boolean initialIsCheckoutNewBranch = OptionsManager.getInstance().isCheckoutNewlyCreatedLocalBranch();
    try {
        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());
        // ------------- Create branch LOCAL_BRANCH_COPY_NAME from 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[] split = firstLeafPath.split("/");
        assertEquals(LOCAL_BRANCH_NAME1, split[split.length - 1]);
        List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(firstLeaf);
        for (AbstractAction abstractAction : actionsForNode) {
            if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.CREATE_BRANCH) + "...")) {
                SwingUtilities.invokeLater(() -> {
                    abstractAction.actionPerformed(null);
                });
                flushAWT();
                JDialog createBranchDialog = findDialog(translator.getTranslation(Tags.CREATE_BRANCH));
                JCheckBox checkoutBranchCheckBox = findCheckBox(createBranchDialog, Tags.CHECKOUT_BRANCH);
                assertNotNull(checkoutBranchCheckBox);
                checkoutBranchCheckBox.setSelected(true);
                flushAWT();
                JTextField branchNameTextField = findComponentNearJLabel(createBranchDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
                branchNameTextField.setText(LOCAL_BRANCH_COPY_NAME);
                JButton okButton = findFirstButton(createBranchDialog, "Create");
                if (okButton != null) {
                    okButton.setEnabled(true);
                    okButton.doClick();
                }
                break;
            }
        }
        sleep(500);
        gitAccess.fetch();
        branchManagementPanel.refreshBranches();
        flushAWT();
        root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
        StringBuilder actualTree = new StringBuilder();
        BranchManagementTest.serializeTree(actualTree, root);
        assertEquals("localRepository\n" + "  refs/heads/\n" + "    refs/heads/LocalBranch\n" + "    refs/heads/LocalBranch2\n" + "    refs/heads/LocalBranchCopy\n" + "    refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME + "\n", actualTree.toString());
        assertEquals("LocalBranchCopy", gitAccess.getBranchInfo().getBranchName());
    } finally {
        OptionsManager.getInstance().setCheckoutNewlyCreatedLocalBranch(initialIsCheckoutNewBranch);
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) File(java.io.File) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 5 with GitControllerBase

use of com.oxygenxml.git.service.GitControllerBase in project oxygen-git-client-addon by oxygenxml.

the class BranchActionsTest method testCheckoutRemoteBranchAction.

/**
 * Tests the action of checkout a remote branch.
 *
 * @throws Exception
 */
public void testCheckoutRemoteBranchAction() throws Exception {
    gitAccess.setRepositorySynchronously(REMOTE_TEST_REPOSITORY);
    File file = new File(REMOTE_TEST_REPOSITORY + "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    // Make the first commit for the remote repository and create a branch for it.
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    // Create new remote branches
    gitAccess.createBranch(REMOTE_BRANCH_NAME1);
    gitAccess.createBranch(REMOTE_BRANCH_NAME2);
    gitAccess.setRepositorySynchronously(LOCAL_TEST_REPOSITORY);
    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 last branch in the tree: REMOTE_BRANCH_NAME2, with the name REMOTE_BRANCH_NAME2_COPY-------------
    GitTreeNode lastLeaf = (GitTreeNode) root.getLastLeaf();
    String lastLeafPath = (String) lastLeaf.getUserObject();
    assertTrue(lastLeafPath.contains(Constants.R_REMOTES));
    String[] branchPath = lastLeafPath.split("/");
    assertEquals(REMOTE_BRANCH_NAME2, branchPath[branchPath.length - 1]);
    AbstractAction checkoutAction = branchTreeMenuActionsProvider.getCheckoutAction(lastLeaf);
    if (checkoutAction != null) {
        SwingUtilities.invokeLater(() -> {
            checkoutAction.actionPerformed(null);
        });
        JDialog checkoutBranchDialog = findDialog(translator.getTranslation(Tags.CHECKOUT_BRANCH));
        if (checkoutBranchDialog != null) {
            JTextField branchNameTextField = findComponentNearJLabel(checkoutBranchDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
            branchNameTextField.setText(REMOTE_BRANCH_NAME2_COPY);
            JButton firstButtonFound = findFirstButton(checkoutBranchDialog, "Checkout");
            if (firstButtonFound != null) {
                firstButtonFound.setEnabled(true);
                firstButtonFound.doClick();
            }
        }
    }
    sleep(500);
    gitAccess.fetch();
    branchManagementPanel.refreshBranches();
    flushAWT();
    root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
    StringBuilder actualTree = new StringBuilder();
    BranchManagementTest.serializeTree(actualTree, root);
    assertEquals("localRepository\n" + "  refs/heads/\n" + "    refs/heads/RemoteBranch2Copy\n" + "  refs/remotes/\n" + "    refs/remotes/origin/\n" + "      refs/remotes/origin/" + GitAccess.DEFAULT_BRANCH_NAME + "\n" + "      refs/remotes/origin/RemoteBranch\n" + "      refs/remotes/origin/RemoteBranch2\n" + "", actualTree.toString());
    // ------------- Checkout the previous branch in the tree: REMOTE_BRANCH_NAME1, with the name REMOTE_BRANCH_NAME1_COPY-------------
    GitTreeNode previousLeaf = (GitTreeNode) lastLeaf.getPreviousLeaf();
    String previousLeafPath = (String) previousLeaf.getUserObject();
    assertTrue(lastLeafPath.contains(Constants.R_REMOTES));
    branchPath = previousLeafPath.split("/");
    assertEquals(REMOTE_BRANCH_NAME1, branchPath[branchPath.length - 1]);
    List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(previousLeaf);
    for (AbstractAction abstractAction : actionsForNode) {
        if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.CHECKOUT) + "...")) {
            SwingUtilities.invokeLater(() -> {
                abstractAction.actionPerformed(null);
            });
            JDialog checkoutDialog = findDialog(translator.getTranslation(Tags.CHECKOUT_BRANCH));
            if (checkoutDialog != null) {
                JTextField branchNameTextField = findComponentNearJLabel(checkoutDialog, translator.getTranslation(Tags.BRANCH_NAME) + ": ", JTextField.class);
                branchNameTextField.setText(REMOTE_BRANCH_NAME1_COPY);
                JButton firstButtonFound = findFirstButton(checkoutDialog, "Checkout");
                if (firstButtonFound != null) {
                    firstButtonFound.setEnabled(true);
                    firstButtonFound.doClick();
                }
            }
            break;
        }
    }
    sleep(500);
    gitAccess.fetch();
    branchManagementPanel.refreshBranches();
    flushAWT();
    root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
    actualTree = new StringBuilder();
    BranchManagementTest.serializeTree(actualTree, root);
    assertEquals("localRepository\n" + "  refs/heads/\n" + "    refs/heads/RemoteBranch2Copy\n" + "    refs/heads/RemoteBranchCopy\n" + "  refs/remotes/\n" + "    refs/remotes/origin/\n" + "      refs/remotes/origin/" + GitAccess.DEFAULT_BRANCH_NAME + "\n" + "      refs/remotes/origin/RemoteBranch\n" + "      refs/remotes/origin/RemoteBranch2\n" + "", actualTree.toString());
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) JTextField(javax.swing.JTextField) GitControllerBase(com.oxygenxml.git.service.GitControllerBase) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) File(java.io.File) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

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