Search in sources :

Example 31 with GitController

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

the class GitAccessConflictTest method testPullWithConflicts_Rebase_ResolveUsingMine_Continue.

/**
 * Pull (rebase) with conflict. Resolve using mine and continue rebase.
 *
 * @throws Exception
 */
@Test
public void testPullWithConflicts_Rebase_ResolveUsingMine_Continue() throws Exception {
    // ----------------
    // LOCAL 1
    // ----------------
    gitAccess = GitAccess.getInstance();
    gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
    // Create a file in the remote.
    File remoteParent = new File(FIRST_LOCAL_TEST_REPOSITPRY);
    remoteParent.mkdirs();
    File local1File = new File(FIRST_LOCAL_TEST_REPOSITPRY, "test.txt");
    writeToFile(local1File, "original");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("Primul");
    push("", "");
    // ----------------
    // LOCAL 2
    // ----------------
    gitAccess.setRepositorySynchronously(SECOND_LOCAL_TEST_REPOSITORY);
    PullResponse pull = pull("", "", PullType.MERGE_FF, false);
    assertEquals(PullStatus.OK.toString(), pull.getStatus().toString());
    File local2File = new File(SECOND_LOCAL_TEST_REPOSITORY, "test.txt");
    assertEquals("original", getFileContent(local2File));
    writeToFile(local2File, "changed in local 2");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("Al doilea");
    push("", "");
    // ----------------
    // LOCAL 1
    // ----------------
    gitAccess.setRepositorySynchronously(FIRST_LOCAL_TEST_REPOSITPRY);
    writeToFile(local1File, "changed in local 1");
    final StringBuilder pullWithConflictsSB = new StringBuilder();
    boolean[] wasRebaseInterrupted = new boolean[1];
    final String[] pullFailedMessage = new String[1];
    GitController pc = new GitController(gitAccess) {

        @Override
        protected void showPullFailedBecauseOfCertainChanges(List<String> changes, String message) {
            pullFailedMessage[0] = message;
        }

        @Override
        protected void showPullSuccessfulWithConflicts(PullResponse response) {
            pullWithConflictsSB.append(response);
        }

        @Override
        protected void showRebaseInProgressDialog() {
            wasRebaseInterrupted[0] = true;
        }
    };
    final StringBuilder b = new StringBuilder();
    TestUtil.collectPushPullEvents(pc, b);
    // Get conflict
    assertEquals("changed in local 1", getFileContent(local1File));
    gitAccess.add(new FileStatus(GitChangeType.ADD, "test.txt"));
    gitAccess.commit("Another");
    pc.pull(PullType.REBASE).get();
    assertNull(pullFailedMessage[0]);
    assertFalse(wasRebaseInterrupted[0]);
    assertEquals("Status: CONFLICTS Conflicting files: [test.txt]", pullWithConflictsSB.toString());
    assertTrue(getFileContent(local1File).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
    // Show the "Interrupted rebase" dialog
    pc.pull(PullType.REBASE).get();
    assertTrue(wasRebaseInterrupted[0]);
    Status status = gitAccess.getGit().status().call();
    assertEquals("[test.txt]", status.getConflicting().toString());
    assertTrue(getFileContent(local1File).startsWith("<<<<<<< Upstream, based on branch '" + GitAccess.DEFAULT_BRANCH_NAME + "' of file:"));
    GitControllerBase gitCtrl = new GitControllerBase(gitAccess) {

        @Override
        protected boolean isUserOKWithResolvingRebaseConflictUsingMineOrTheirs(ConflictResolution cmd) {
            return cmd == ConflictResolution.RESOLVE_USING_MINE;
        }
    };
    gitCtrl.asyncResolveUsingMine(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
    sleep(700);
    // When having a conflict while rebasing, 'Mine' and 'Theirs' become reversed
    assertEquals("When having a conflict while rebasing, 'Mine' and 'Theirs' become reversed ", "changed in local 2", getFileContent(local1File));
    GitStatus gitStatus = gitAccess.getStatus();
    assertTrue(gitStatus.getStagedFiles().isEmpty());
    assertTrue(gitStatus.getUnstagedFiles().isEmpty());
    RepositoryState repositoryState = gitAccess.getRepository().getRepositoryState();
    assertEquals(RepositoryState.REBASING_MERGE, repositoryState);
    gitAccess.continueRebase();
    sleep(700);
    repositoryState = gitAccess.getRepository().getRepositoryState();
    assertEquals(RepositoryState.SAFE, repositoryState);
    assertEquals(0, gitAccess.getPullsBehind());
    assertEquals(0, gitAccess.getPushesAhead());
    PushResponse pushResp = push("", "");
    assertEquals(RemoteRefUpdate.Status.UP_TO_DATE, pushResp.getStatus());
    assertEquals("Push_Up_To_Date", pushResp.getMessage());
}
Also used : Status(org.eclipse.jgit.api.Status) FileStatus(com.oxygenxml.git.service.entities.FileStatus) FileStatus(com.oxygenxml.git.service.entities.FileStatus) GitController(com.oxygenxml.git.view.event.GitController) RepositoryState(org.eclipse.jgit.lib.RepositoryState) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 32 with GitController

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

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

the class FlatView7Test method testSettingsMenu.

/**
 * <p><b>Description:</b> list the Settings menu actions.</p>
 * <p><b>Bug ID:</b> EXM-46442</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testSettingsMenu() throws Exception {
    final JMenu settingsMenu = new GitActionsMenuBar(new GitActionsManager(new GitController(), null, null, null)).getSettingsMenu();
    assertEquals(2, settingsMenu.getItemCount());
    assertEquals(Tags.RESET_ALL_CREDENTIALS, settingsMenu.getItem(0).getText());
    assertEquals(Tags.PREFERENCES, settingsMenu.getItem(1).getText());
}
Also used : GitActionsMenuBar(com.oxygenxml.git.view.actions.GitActionsMenuBar) GitController(com.oxygenxml.git.view.event.GitController) JMenu(javax.swing.JMenu) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 34 with GitController

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

the class FlatViewTestBase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    GitController gitController = new GitController() {

        @Override
        protected void showPullSuccessfulWithConflicts(PullResponse response) {
        // Nothing to do.
        }
    };
    gitActionsManager = new GitActionsManager(gitController, null, null, refreshSupport);
    stagingPanel = new StagingPanel(refreshSupport, gitController, null, gitActionsManager) {

        @Override
        protected ToolbarPanel createToolbar(GitActionsManager gitActionsManager) {
            // not to create it anymore
            return null;
        }
    };
    // TODO: Maybe move this init on the StagingPanel constructor.
    // Careful not to create a cycle.
    refreshSupport.setStagingPanel(stagingPanel);
    mainFrame = new JFrame("Git test");
    mainFrame.getContentPane().add(stagingPanel, BorderLayout.CENTER);
    mainFrame.setSize(new Dimension(400, 600));
    mainFrame.setVisible(true);
    // When the GUI is created some tasks are scheduled on AWT and Git thread.
    // Better wait for them so they don't interact with the tests.
    flushAWT();
    waitForScheduler();
}
Also used : PullResponse(com.oxygenxml.git.service.PullResponse) JFrame(javax.swing.JFrame) GitController(com.oxygenxml.git.view.event.GitController) Dimension(java.awt.Dimension) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 35 with GitController

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

the class ToolbarPanelTest method testNoOfSkippedCommitsInPushPullToolbars.

/**
 * <p><b>Description:</b> get the number of skipped commits in push/pull tooltips.</p>
 * <p><b>Bug ID:</b> EXM-44564</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testNoOfSkippedCommitsInPushPullToolbars() throws Exception {
    final GitController gitController = new GitController();
    final ToolbarPanel toolbarPanel = new ToolbarPanel(gitController, new GitActionsManager(gitController, null, null, null));
    assertEquals(0, toolbarPanel.getNoOfSkippedCommits(5));
    assertEquals(1, toolbarPanel.getNoOfSkippedCommits(6));
    assertEquals(2, toolbarPanel.getNoOfSkippedCommits(7));
}
Also used : GitController(com.oxygenxml.git.view.event.GitController) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

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