Search in sources :

Example 16 with GitController

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

the class BranchMergingTest method testBranchMergingWithConflict.

/**
 * <p><b>Description:</b>Tests the branch merging. Conflict happens.</p>
 * <p><b>Bug ID:</b> EXM-43410</p>
 *
 * @author gabriel_nedianu
 *
 * @throws Exception
 */
public void testBranchMergingWithConflict() throws Exception {
    JDialog conflictMergeDialog = null;
    try {
        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"));
        refreshSupport.call();
        gitAccess.commit("First local commit on main.");
        gitAccess.createBranch(LOCAL_BRANCH_NAME1);
        GitControllerBase mock = new GitController();
        BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
        branchManagementPanel.refreshBranches();
        flushAWT();
        refreshSupport.call();
        // ------------- 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"));
        refreshSupport.call();
        gitAccess.commit("Commit on secondary branch");
        refreshSupport.call();
        // ------------- 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"));
        refreshSupport.call();
        gitAccess.commit("2nd commit on main branch");
        refreshSupport.call();
        // 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));
        refreshSupport.call();
        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
        JDialog mergeOkDialog = findDialog(translator.getTranslation(Tags.MERGE_BRANCHES));
        JButton mergeOkButton = findFirstButton(mergeOkDialog, translator.getTranslation(Tags.MERGE));
        mergeOkButton.doClick();
        flushAWT();
        sleep(200);
        waitForScheduler();
        conflictMergeDialog = findDialog(translator.getTranslation(Tags.MERGE_CONFLICTS_TITLE));
        System.out.println(conflictMergeDialog);
        assertNotNull(conflictMergeDialog);
        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" + ">>>>>>>"));
    } finally {
        if (conflictMergeDialog != null) {
            conflictMergeDialog.setVisible(false);
            conflictMergeDialog.dispose();
        }
    }
}
Also used : GitControllerBase(com.oxygenxml.git.service.GitControllerBase) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitTreeNode(com.oxygenxml.git.view.GitTreeNode) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) AbstractAction(javax.swing.AbstractAction) JDialog(javax.swing.JDialog)

Example 17 with GitController

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

the class BranchMergingTest method testBranchMerging.

/**
 * <p><b>Description:</b>Tests the branch merging.</p>
 * <p><b>Bug ID:</b> EXM-43410</p>
 *
 * @author gabriel_nedianu
 *
 * @throws Exception
 */
public void testBranchMerging() throws Exception {
    File file = new File(LOCAL_TEST_REPOSITORY, "local.txt");
    file.createNewFile();
    setFileContent(file, "local content");
    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();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(mock);
    branchManagementPanel.refreshBranches();
    flushAWT();
    refreshSupport.call();
    GitTreeNode root = (GitTreeNode) (branchManagementPanel.getTree().getModel().getRoot());
    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]);
    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 10");
    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
    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
    JDialog mergeOkDialog = findDialog(translator.getTranslation(Tags.MERGE_BRANCHES));
    JButton mergeOkButton = findFirstButton(mergeOkDialog, translator.getTranslation(Tags.MERGE));
    mergeOkButton.doClick();
    sleep(200);
    assertEquals("local content for merging", TestUtil.read(file.toURI().toURL()));
}
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 18 with GitController

use of com.oxygenxml.git.view.event.GitController 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 19 with GitController

use of com.oxygenxml.git.view.event.GitController 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 20 with GitController

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

the class GitCheckoutConflictTest method testSwitchBranchFromGitBranchManager_checkoutConflict_2.

/**
 * <p><b>Description:</b> try to switch branch from Git Staging.
 * 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_2() 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 gitCtrl = new GitController();
    BranchManagementPanel branchManagementPanel = new BranchManagementPanel(gitCtrl);
    branchManagementPanel.refreshBranches();
    flushAWT();
    BranchSelectionCombo branchesCombo = new BranchSelectionCombo((GitController) gitCtrl);
    branchesCombo.refresh();
    SwingUtilities.invokeLater(() -> branchesCombo.setSelectedIndex(1));
    flushAWT();
    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) BranchSelectionCombo(com.oxygenxml.git.view.staging.BranchSelectionCombo) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) BranchManagementPanel(com.oxygenxml.git.view.branches.BranchManagementPanel) Test(org.junit.Test)

Aggregations

GitController (com.oxygenxml.git.view.event.GitController)66 File (java.io.File)54 FileStatus (com.oxygenxml.git.service.entities.FileStatus)48 JButton (javax.swing.JButton)29 Test (org.junit.Test)28 JDialog (javax.swing.JDialog)24 Repository (org.eclipse.jgit.lib.Repository)21 AbstractAction (javax.swing.AbstractAction)19 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)18 GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)18 JFrame (javax.swing.JFrame)15 StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)14 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)13 ArrayList (java.util.ArrayList)12 List (java.util.List)12 JTextField (javax.swing.JTextField)10 BranchManagementPanel (com.oxygenxml.git.view.branches.BranchManagementPanel)8 BranchTreeMenuActionsProvider (com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider)7 ToolbarPanel (com.oxygenxml.git.view.staging.ToolbarPanel)7 JCheckBox (javax.swing.JCheckBox)7