Search in sources :

Example 21 with GitTreeNode

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

the class GitCheckoutConflict2Test method testCheckoutNewBranchWhenRepoInConflict_checkoutConflict_2.

/**
 * <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, but not on the resource that is in pull conflict.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testCheckoutNewBranchWhenRepoInConflict_checkoutConflict_2() 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
    gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    // change file.txt to create checkout conflict
    writeToFile(new File(SECOND_LOCAL_TEST_REPOSITORY + "/file.txt"), "new changes");
    ;
    gitAccess.add(new FileStatus(GitChangeType.ADD, "file.txt"));
    // 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(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 22 with GitTreeNode

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

the class GitCheckoutConflict2Test method testCheckoutNewBranch_checkoutConflict_1.

/**
 * <p><b>Description:</b> try to switch to a newly created branch from Git Branch Manager.
 * Repo is not in conflict.
 * The branch checkout generates a checkout conflict.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testCheckoutNewBranch_checkoutConflict_1() throws Exception {
    // Push from main branch
    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("", "");
    // Create new_branch, change file and commit
    gitAccess.createBranchFromLocalBranch("new_branch", gitAccess.getGit().getRepository().getFullBranch());
    writeToFile(new File(FIRST_LOCAL_TEST_REPOSITPRY + "/test.txt"), "altfel");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("commit on ew branch");
    // Move to main branch and change file
    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 gitCtrl = new GitController();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(gitCtrl);
    branchManagementPanel.refreshBranches();
    sleep(500);
    BranchTreeMenuActionsProvider branchTreeMenuActionsProvider = new BranchTreeMenuActionsProvider(gitCtrl);
    // 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);
                SwingUtilities.invokeLater(() -> okButton.doClick());
                flushAWT();
            }
            break;
        }
    }
    sleep(1000);
    Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    JButton yesButton = TestUtil.findButton(focusedWindow, translator.getTranslation(Tags.MOVE_CHANGES));
    yesButton.doClick();
    flushAWT();
    sleep(1000);
    assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
    assertEquals("Cannot_checkout_new_branch_because_uncommitted_changes", 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) 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 23 with GitTreeNode

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

the class GitCheckoutConflictTest method testSwitchBranchWhenRepoInConflict_checkoutConflict_1.

/**
 * <p><b>Description:</b> try to switch branch from Git Branch Manager when repo is in conflict state.
 * The branch switch also generates a checkout conflict.</p>
 * <p><b>Bug ID:</b> EXM-47439</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
@Test
public void testSwitchBranchWhenRepoInConflict_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(Tags.CHECKOUT)) {
            SwingUtilities.invokeLater(() -> abstractAction.actionPerformed(null));
            break;
        }
    }
    sleep(500);
    assertEquals(GitAccess.DEFAULT_BRANCH_NAME, gitAccess.getRepository().getBranch());
    assertEquals("Branch_switch_when_repo_in_conflict_error_msg", errMsg[0]);
}
Also used : BranchTreeMenuActionsProvider(com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) TreePath(javax.swing.tree.TreePath) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) BranchManagementPanel(com.oxygenxml.git.view.branches.BranchManagementPanel) AbstractAction(javax.swing.AbstractAction) Test(org.junit.Test)

Example 24 with GitTreeNode

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

the class GitAccessRevertMergingConflictsTest method testRevertCommitWithRepoInConflict.

/**
 * <p><b>Description:</b> test the "Revert commit" action when the repo has conflicts.</p>
 * <p><b>Bug ID:</b> EXM-47154</p>
 *
 * @author Tudosie Razvan
 *
 * @throws Exception
 */
@Test
public void testRevertCommitWithRepoInConflict() throws Exception {
    File file1 = new File(LOCAL_TEST_REPOSITORY, "local1.txt");
    File file2 = new File(LOCAL_TEST_REPOSITORY, "local2.txt");
    file1.createNewFile();
    file2.createNewFile();
    setFileContent(file1, "local file 1 content");
    setFileContent(file2, "local file 2 content");
    // Make the first commit for the local repository and create a new branch
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
    gitAccess.commit("First local commit on main.");
    gitAccess.createBranch(LOCAL_BRANCH_NAME1);
    GitControllerBase mock = new GitController();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
    branchManagementPanel.refreshBranches();
    flushAWT();
    // ------------- Checkout branch: LOCAL_BRANCH_NAME1 -------------
    gitAccess.setBranch(LOCAL_BRANCH_NAME1);
    // Commit on this branch
    setFileContent(file1, "local file 1 on new branch");
    setFileContent(file2, "local file 2 on new branch");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
    gitAccess.commit("Commit on secondary branch");
    // ------------- Move to the main branch and commit something there
    // ---------------
    gitAccess.setBranch(GitAccess.DEFAULT_BRANCH_NAME);
    setFileContent(file1, "local file 1 modifications");
    setFileContent(file2, "local file 2 modifications");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local1.txt"));
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local2.txt"));
    gitAccess.commit("2nd commit on main branch");
    // 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();
    // Confirm merge dialog
    JDialog mergeOkDialog = findDialog(translator.getTranslation(Tags.MERGE_BRANCHES));
    JButton mergeOkButton = findFirstButton(mergeOkDialog, translator.getTranslation(Tags.YES));
    mergeOkButton.doClick();
    flushAWT();
    sleep(300);
    JDialog conflictMergeDialog = findDialog(translator.getTranslation(Tags.MERGE_CONFLICTS_TITLE));
    assertNotNull(conflictMergeDialog);
    conflictMergeDialog.setVisible(false);
    conflictMergeDialog.dispose();
    flushAWT();
    sleep(200);
    assertTrue(TestUtil.read(file1.toURI().toURL()).contains("<<<<<<< HEAD\n" + "local file 1 modifications\n" + "=======\n" + "local file 1 on new branch\n" + ">>>>>>>"));
    assertTrue(TestUtil.read(file2.toURI().toURL()).contains("<<<<<<< HEAD\n" + "local file 2 modifications\n" + "=======\n" + "local file 2 on new branch\n" + ">>>>>>>"));
    List<CommitCharacteristics> commitsCharacteristics = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker());
    String initialHistory = "[ Uncommitted_changes , DATE , * , * , null , null ]\n" + "[ 2nd commit on main branch , DATE , AlexJitianu <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ First local commit on main. , DATE , AlexJitianu <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Added a new file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ Modified a file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 4 , AlexJitianu , [5] ]\n" + "[ First commit. , DATE , AlexJitianu <alex_jitianu@sync.ro> , 5 , AlexJitianu , null ]\n" + "";
    String regex = "(([0-9])|([0-2][0-9])|([3][0-1]))\\ (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\ \\d{4}";
    assertEquals(initialHistory, dumpHistory(commitsCharacteristics).replaceAll(regex, "DATE"));
    CommitCharacteristics commitToRevert = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, new RenameTracker()).get(4);
    RevertCommitAction revertAction = new RevertCommitAction(commitToRevert);
    SwingUtilities.invokeLater(() -> revertAction.actionPerformed(null));
    flushAWT();
    JDialog revertConfirmationDlg = findDialog(Tags.REVERT_COMMIT);
    JTextArea confirmationTextArea = findFirstTextArea(revertConfirmationDlg);
    assertEquals(Tags.REVERT_COMMIT_CONFIRMATION, confirmationTextArea.getText().toString());
    JButton revertOkButton = findFirstButton(revertConfirmationDlg, Tags.YES);
    revertOkButton.doClick();
    flushAWT();
    sleep(300);
    assertEquals("", errMsg[0]);
}
Also used : RenameTracker(com.oxygenxml.git.view.history.RenameTracker) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JTextArea(javax.swing.JTextArea) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) RevertCommitAction(com.oxygenxml.git.view.history.actions.RevertCommitAction) BranchTreeMenuActionsProvider(com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) File(java.io.File) BranchManagementPanel(com.oxygenxml.git.view.branches.BranchManagementPanel) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog) Test(org.junit.Test)

Example 25 with GitTreeNode

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

the class ChangesPanel method treatEnterKeyPressedOnTreeSelection.

/**
 * Enter key was pressed when having something selected in the resources tree. Treat the event.
 */
private void treatEnterKeyPressedOnTreeSelection() {
    TreePath pathForRow = null;
    int[] selectionRows = tree.getSelectionRows();
    if (selectionRows != null && selectionRows.length > 0) {
        pathForRow = tree.getPathForRow(selectionRows[selectionRows.length - 1]);
    }
    if (pathForRow != null) {
        StagingResourcesTreeModel model = (StagingResourcesTreeModel) tree.getModel();
        String stringPath = TreeUtil.getStringPath(pathForRow);
        GitTreeNode node = TreeUtil.getTreeNodeFromString(model, stringPath);
        if (node != null && model.isLeaf(node) && !model.getRoot().equals(node)) {
            FileStatus file = model.getFileByPath(stringPath);
            DiffPresenter.showDiff(file, gitController);
        }
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) TreePath(javax.swing.tree.TreePath) GitTreeNode(com.oxygenxml.git.view.GitTreeNode)

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