Search in sources :

Example 1 with RevertCommitAction

use of com.oxygenxml.git.view.history.actions.RevertCommitAction in project oxygen-git-client-addon by oxygenxml.

the class HistoryViewContextualMenuPresenter method populateActions4SingleSelection.

/**
 * Contributes the contextual actions for the given file, at the given revision/commit.
 *
 * @param jPopupMenu            Contextual menu in which to put the actions.
 * @param filePath              File path.
 * @param commitCharacteristics Revision/commit data.
 *
 * @throws IOException If it fails.
 * @throws GitAPIException If it fails.
 */
private void populateActions4SingleSelection(JPopupMenu jPopupMenu, String filePath, CommitCharacteristics commitCharacteristics) throws IOException, GitAPIException {
    if (filePath != null) {
        Optional<FileStatus> fileStatusOptional = getFileStatus(filePath, commitCharacteristics);
        fileStatusOptional.ifPresent(fileStatus -> populateContextActionsForFile(jPopupMenu, fileStatus, commitCharacteristics, true));
    }
    if (filePath != null) {
        jPopupMenu.addSeparator();
    }
    String commitId = commitCharacteristics.getCommitId();
    if (!GitAccess.UNCOMMITED_CHANGES.getCommitId().equals(commitId)) {
        jPopupMenu.add(new CreateBranchFromCommitAction(commitId));
        jPopupMenu.add(new CreateTagAction(commitId));
        jPopupMenu.add(new CheckoutCommitAction(commitCharacteristics.getPlotCommit()));
        jPopupMenu.addSeparator();
        jPopupMenu.add(new RevertCommitAction(commitCharacteristics));
        jPopupMenu.add(new ResetBranchToCommitAction(commitCharacteristics));
    }
}
Also used : RevertCommitAction(com.oxygenxml.git.view.history.actions.RevertCommitAction) FileStatus(com.oxygenxml.git.service.entities.FileStatus) CheckoutCommitAction(com.oxygenxml.git.view.history.actions.CheckoutCommitAction) ResetBranchToCommitAction(com.oxygenxml.git.view.history.actions.ResetBranchToCommitAction) CreateTagAction(com.oxygenxml.git.view.history.actions.CreateTagAction) CreateBranchFromCommitAction(com.oxygenxml.git.view.history.actions.CreateBranchFromCommitAction)

Example 2 with RevertCommitAction

use of com.oxygenxml.git.view.history.actions.RevertCommitAction 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 3 with RevertCommitAction

use of com.oxygenxml.git.view.history.actions.RevertCommitAction in project oxygen-git-client-addon by oxygenxml.

the class RevertCommitTest method testRevertCommit_cannotRevertFirstVersion.

/**
 * <p><b>Description:</b> cannot revert first version.</p>
 * <p><b>Bug ID:</b> EXM-47154</p>
 *
 * @author Tudosie Razvan
 *
 * @throws Exception
 */
public void testRevertCommit_cannotRevertFirstVersion() throws Exception {
    // The history at this moment
    List<CommitCharacteristics> commitsCharacteristics = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String expected = "[ Added a new file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Modified a file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , DATE , AlexJitianu <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
    assertEquals(expected, dumpHistory(commitsCharacteristics).replaceAll(DATE_REGEX, "DATE"));
    CommitCharacteristics commitToRevert = commitsCharacteristics.get(2);
    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);
    assertEquals("", errMsg[0]);
    SwingUtilities.invokeLater(() -> revertOkButton.doClick());
    flushAWT();
    sleep(300);
    assertTrue(errMsg[0].contains("Cannot revert"));
    // The history stays the same
    commitsCharacteristics = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    expected = "[ Added a new file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Modified a file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , DATE , AlexJitianu <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
    assertEquals(expected, dumpHistory(commitsCharacteristics).replaceAll(DATE_REGEX, "DATE"));
}
Also used : RevertCommitAction(com.oxygenxml.git.view.history.actions.RevertCommitAction) JTextArea(javax.swing.JTextArea) JButton(javax.swing.JButton) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) JDialog(javax.swing.JDialog)

Example 4 with RevertCommitAction

use of com.oxygenxml.git.view.history.actions.RevertCommitAction in project oxygen-git-client-addon by oxygenxml.

the class RevertCommitTest method testRevertCommit.

/**
 * <p><b>Description:</b> revert commit.</p>
 * <p><b>Bug ID:</b> EXM-47154</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testRevertCommit() throws Exception {
    // The history at this moment
    List<CommitCharacteristics> commitsCharacteristics = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String expected = "[ Added a new file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Modified a file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ First commit. , DATE , AlexJitianu <alex_jitianu@sync.ro> , 3 , AlexJitianu , null ]\n" + "";
    assertEquals(expected, dumpHistory(commitsCharacteristics).replaceAll(DATE_REGEX, "DATE"));
    CommitCharacteristics commitToRevert = commitsCharacteristics.get(1);
    RevertCommitAction revertAction = new RevertCommitAction(commitToRevert);
    SwingUtilities.invokeLater(() -> revertAction.actionPerformed(null));
    flushAWT();
    sleep(200);
    JDialog revertConfirmationDlg = findDialog(Tags.REVERT_COMMIT);
    JTextArea confirmationTextArea = findFirstTextArea(revertConfirmationDlg);
    assertEquals(Tags.REVERT_COMMIT_CONFIRMATION, confirmationTextArea.getText().toString());
    JButton revertOkButton = findFirstButton(revertConfirmationDlg, Tags.YES);
    SwingUtilities.invokeLater(() -> revertOkButton.doClick());
    flushAWT();
    sleep(300);
    // New commit added (for the reverted changes)
    commitsCharacteristics = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    assertEquals(4, commitsCharacteristics.size());
    assertTrue(commitsCharacteristics.get(0).getCommitMessage().startsWith("Revert \"Modified a file\""));
}
Also used : RevertCommitAction(com.oxygenxml.git.view.history.actions.RevertCommitAction) JTextArea(javax.swing.JTextArea) JButton(javax.swing.JButton) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) JDialog(javax.swing.JDialog)

Example 5 with RevertCommitAction

use of com.oxygenxml.git.view.history.actions.RevertCommitAction in project oxygen-git-client-addon by oxygenxml.

the class RevertCommitTest method testRevertCommit_warningWhenConflictGenerated.

/**
 * <p><b>Description:</b> show warning when conflict is generated.</p>
 * <p><b>Bug ID:</b> EXM-48678</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testRevertCommit_warningWhenConflictGenerated() throws Exception {
    setFileContent(firstFile, "<modified content 2>");
    gitAccess.add(new FileStatus(GitChangeType.ADD, LOCAL_FILE_NAME));
    gitAccess.commit("Modified a file again");
    // The history at this moment
    List<CommitCharacteristics> commitsCharacteristics = gitAccess.getCommitsCharacteristics(HistoryStrategy.CURRENT_BRANCH, null, null);
    String expected = "[ Modified a file again , DATE , AlexJitianu <alex_jitianu@sync.ro> , 1 , AlexJitianu , [2] ]\n" + "[ Added a new file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 2 , AlexJitianu , [3] ]\n" + "[ Modified a file , DATE , AlexJitianu <alex_jitianu@sync.ro> , 3 , AlexJitianu , [4] ]\n" + "[ First commit. , DATE , AlexJitianu <alex_jitianu@sync.ro> , 4 , AlexJitianu , null ]\n" + "";
    assertEquals(expected, dumpHistory(commitsCharacteristics).replaceAll(DATE_REGEX, "DATE"));
    // Revert commit that will trigger conflict
    CommitCharacteristics commitToRevert = commitsCharacteristics.get(2);
    RevertCommitAction revertAction = new RevertCommitAction(commitToRevert);
    SwingUtilities.invokeLater(() -> revertAction.actionPerformed(null));
    flushAWT();
    sleep(200);
    JDialog revertConfirmationDlg = findDialog(Tags.REVERT_COMMIT);
    JTextArea confirmationTextArea = findFirstTextArea(revertConfirmationDlg);
    assertEquals(Tags.REVERT_COMMIT_CONFIRMATION, confirmationTextArea.getText().toString());
    JButton revertOkButton = findFirstButton(revertConfirmationDlg, Tags.YES);
    SwingUtilities.invokeLater(() -> revertOkButton.doClick());
    flushAWT();
    sleep(300);
    JDialog dlg = findDialog(Tags.REVERT_COMMIT);
    assertNotNull(dlg);
    JTextArea textArea = findFirstTextArea(dlg);
    assertEquals(Tags.REVERT_COMMIT_RESULTED_IN_CONFLICTS, textArea.getText());
    dlg.dispose();
}
Also used : RevertCommitAction(com.oxygenxml.git.view.history.actions.RevertCommitAction) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JTextArea(javax.swing.JTextArea) JButton(javax.swing.JButton) CommitCharacteristics(com.oxygenxml.git.view.history.CommitCharacteristics) JDialog(javax.swing.JDialog)

Aggregations

RevertCommitAction (com.oxygenxml.git.view.history.actions.RevertCommitAction)6 CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)5 JButton (javax.swing.JButton)5 JDialog (javax.swing.JDialog)5 JTextArea (javax.swing.JTextArea)5 FileStatus (com.oxygenxml.git.service.entities.FileStatus)3 Test (org.junit.Test)2 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)1 BranchManagementPanel (com.oxygenxml.git.view.branches.BranchManagementPanel)1 BranchTreeMenuActionsProvider (com.oxygenxml.git.view.branches.BranchTreeMenuActionsProvider)1 GitController (com.oxygenxml.git.view.event.GitController)1 RenameTracker (com.oxygenxml.git.view.history.RenameTracker)1 CheckoutCommitAction (com.oxygenxml.git.view.history.actions.CheckoutCommitAction)1 CreateBranchFromCommitAction (com.oxygenxml.git.view.history.actions.CreateBranchFromCommitAction)1 CreateTagAction (com.oxygenxml.git.view.history.actions.CreateTagAction)1 ResetBranchToCommitAction (com.oxygenxml.git.view.history.actions.ResetBranchToCommitAction)1 File (java.io.File)1 AbstractAction (javax.swing.AbstractAction)1