Search in sources :

Example 31 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class GitCheckoutConflict2Test method testCheckoutNewBranchWhenRepoInConflict_checkoutConflict_1.

/**
 * <p><b>Description:</b> try to switch to a newly created branch from Git Branch Manager
 * when repo is in conflict state.
 * The branch checkout also generates a checkout conflict.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testCheckoutNewBranchWhenRepoInConflict_checkoutConflict_1() throws Exception {
    // Push from first repo
    gitAccess.setRepositorySynchronously(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("", "");
    // Commit from second repo
    gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
    File file = new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
    file.createNewFile();
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "teeeeeest");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("conflict");
    // Change file on the new branch
    gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
    gitAccess.setBranch("new_branch");
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "altfel");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("commit on ew branch");
    // move to main branch
    gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    // Pull to create conflict
    PullResponse pullResp = pull("", "", PullType.MERGE_FF, false);
    assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullResp.toString());
    GitControllerBase mock = new GitController();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
    branchManagementPanel.refreshBranches();
    sleep(500);
    BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
    // Simulate branch checkout from Git Branch Manager view
    GitTreeNode node = new GitTreeNode(new TreePath(new String[] { "refs", "heads", "new_branch" }));
    node.setUserObject("refs/heads/new_branch");
    List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(node);
    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("a_new_day");
            JButton okButton = findFirstButton(createBranchDialog, "Create");
            if (okButton != null) {
                okButton.setEnabled(true);
                okButton.doClick();
            }
            break;
        }
    }
    sleep(500);
    assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
    assertEquals("Cannot_checkout_new_branch_when_having_conflicts", errMsg[0]);
}
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) BranchTreeMenuActionsProvider(com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) TreePath(javax.swing.tree.TreePath) File(java.io.File) BranchManagementPanel(com.oxygenxml.git.view.branches.BranchManagementPanel) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 32 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class GitCheckoutConflict2Test method testCheckoutNewBranchWhenRepoInConflict_succeed_1.

/**
 * <p><b>Description:</b> try to switch to a newly created branch from Git Branch Manager
 * when repo is in conflict state.
 * This should succeed.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testCheckoutNewBranchWhenRepoInConflict_succeed_1() throws Exception {
    // Push test.txt from first repo
    gitAccess.setRepositorySynchronously(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("", "");
    // Commit test.txt from second repo
    gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
    File file = new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt");
    file.createNewFile();
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/test.txt"), "teeeeeest");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("conflict");
    // Change file.txt file on the new branch
    gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
    gitAccess.setBranch("new_branch");
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/file.txt"), "altfel");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "file.txt"));
    gitAccess.commit("commit on nnew branch");
    // move to main branch
    gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    // Pull to create conflict o text.txt
    PullResponse pullResp = pull("", "", PullType.MERGE_FF, false);
    assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullResp.toString());
    GitControllerBase mock = new GitController();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
    branchManagementPanel.refreshBranches();
    sleep(500);
    BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
    // Simulate branch checkout from Git Branch Manager view
    GitTreeNode node = new GitTreeNode(new TreePath(new String[] { "refs", "heads", "new_branch" }));
    node.setUserObject("refs/heads/new_branch");
    List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(node);
    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("a_new_day");
            JButton okButton = findFirstButton(createBranchDialog, "Create");
            if (okButton != null) {
                okButton.setEnabled(true);
                okButton.doClick();
            }
            break;
        }
    }
    sleep(500);
    assertEquals("a_new_day", gitAccess.getRepository().getBranch());
}
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) BranchTreeMenuActionsProvider(com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) TreePath(javax.swing.tree.TreePath) File(java.io.File) BranchManagementPanel(com.oxygenxml.git.view.branches.BranchManagementPanel) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 33 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class GitCheckoutConflictTest method testSwitchBranchFromGitBranchManager_checkoutConflict_1.

/**
 * <p><b>Description:</b> try to switch branch from Git Branch Manager.
 * The branch witch generates a checkout conflict.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
@Test
public void testSwitchBranchFromGitBranchManager_checkoutConflict_1() throws Exception {
    // Push from first repo
    gitAccess.setRepositorySynchronously(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("", "");
    // Change file on the new branch
    gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
    gitAccess.setBranch("new_branch");
    writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "altfel");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("commit 2");
    // move to main branch
    gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "new content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    GitControllerBase mock = new GitController();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
    branchManagementPanel.refreshBranches();
    sleep(1000);
    BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(mock);
    // Simulate branch checkout from Git Branch Manager view
    GitTreeNode node = new GitTreeNode(new TreePath(new String[] { "refs", "heads", "new_branch" }));
    node.setUserObject("refs/heads/new_branch");
    List<AbstractAction> actionsForNode = branchTreeMenuActionsProvider.getActionsForNode(node);
    for (AbstractAction abstractAction : actionsForNode) {
        if (abstractAction.getValue(AbstractAction.NAME).equals(Tags.CHECKOUT)) {
            abstractAction.actionPerformed(null);
            break;
        }
    }
    sleep(1000);
    Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    JButton yesButton = TestUtil.findButton(focusedWindow, translator.getTranslation(Tags.MOVE_CHANGES));
    yesButton.doClick();
    sleep(1000);
    assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
    assertEquals("Branch_switch_checkout_conflict_error_msg", errMsg[0]);
}
Also used : Window(java.awt.Window) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) BranchTreeMenuActionsProvider(com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) TreePath(javax.swing.tree.TreePath) File(java.io.File) BranchManagementPanel(com.oxygenxml.git.view.branches.BranchManagementPanel) AbstractAction(javax.swing.AbstractAction) Test(org.junit.Test)

Example 34 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode in project oxygen-git-client-addon by oxygenxml.

the class BranchActionsTest method testDeleteLocalBranchAction.

/**
 * Tests the action of deleting a local branch.
 *
 * @throws Exception
 */
public void testDeleteLocalBranchAction() 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());
    // ------------- Delete 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 == null) {
            // Probably separator. Continue.
            continue;
        }
        if (abstractAction.getValue(AbstractAction.NAME).equals(translator.getTranslation(Tags.DELETE) + "...")) {
            SwingUtilities.invokeLater(() -> {
                abstractAction.actionPerformed(null);
            });
            JDialog deleteBranchDialog = findDialog(translator.getTranslation(Tags.DELETE_BRANCH));
            JButton yesButton = findFirstButton(deleteBranchDialog, translator.getTranslation(Tags.YES));
            yesButton.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/LocalBranch2\n" + "    refs/heads/" + GitAccess.DEFAULT_BRANCH_NAME + "\n", actualTree.toString());
}
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) File(java.io.File) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 35 with GitTreeNode

use of com.oxygenxml.git.view.GitTreeNode 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)

Aggregations

GitTreeNode (com.oxygenxml.git.view.GitTreeNode)49 FileStatus (com.oxygenxml.git.service.entities.FileStatus)33 File (java.io.File)30 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)23 AbstractAction (javax.swing.AbstractAction)19 GitController (com.oxygenxml.git.view.event.GitController)18 JButton (javax.swing.JButton)15 TreePath (javax.swing.tree.TreePath)14 Test (org.junit.Test)14 JDialog (javax.swing.JDialog)13 JTree (javax.swing.JTree)8 BranchManagementPanel (com.oxygenxml.git.view.branches.BranchManagementPanel)7 BranchTreeMenuActionsProvider (com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider)7 JTextField (javax.swing.JTextField)7 JCheckBox (javax.swing.JCheckBox)6 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 JLabel (javax.swing.JLabel)4 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4