Search in sources :

Example 1 with StagingPanel

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

the class OxygenGitPluginExtension method customizeGitStagingView.

/**
 * Customize the Git Staging view.
 *
 * @param viewInfo View information.
 */
private void customizeGitStagingView(final ViewInfo viewInfo, final GitActionsManager gitActionsManager) {
    boolean shouldRecreateStagingPanel = stagingPanel == null;
    if (shouldRecreateStagingPanel) {
        stagingPanel = new StagingPanel(gitRefreshSupport, gitController, OxygenGitPluginExtension.this, gitActionsManager);
        gitRefreshSupport.setStagingPanel(stagingPanel);
    }
    viewInfo.setComponent(stagingPanel);
    GitOperationUtil.installMouseBusyCursor(gitController, stagingPanel);
    gitController.addGitListener(new GitEventAdapter() {

        @Override
        public void operationAboutToStart(GitEventInfo info) {
        // not needed
        }

        @Override
        public void operationSuccessfullyEnded(GitEventInfo info) {
            final GitOperation operation = info.getGitOperation();
            if (operation == GitOperation.CHECKOUT || operation == GitOperation.CONTINUE_REBASE || operation == GitOperation.RESET_TO_COMMIT || operation == GitOperation.OPEN_WORKING_COPY || operation == GitOperation.MERGE || operation == GitOperation.COMMIT || operation == GitOperation.REVERT_COMMIT || operation == GitOperation.STASH_CREATE || operation == GitOperation.STASH_DROP || operation == GitOperation.STASH_APPLY || operation == GitOperation.UPDATE_CONFIG_FILE || operation == GitOperation.STASH_POP || operation == GitOperation.CHECKOUT_FILE || operation == GitOperation.CHECKOUT_COMMIT || operation == GitOperation.CREATE_TAG || operation == GitOperation.DELETE_TAG || operation == GitOperation.DISCARD) {
                gitRefreshSupport.call();
                if (operation == GitOperation.CHECKOUT || operation == GitOperation.MERGE) {
                    try {
                        FileUtil.refreshProjectView();
                    } catch (NoRepositorySelected e) {
                        LOGGER.debug(e.getMessage(), e);
                    }
                } else if (operation == GitOperation.OPEN_WORKING_COPY && GitAccess.getInstance().getBranchInfo().isDetached()) {
                    treatDetachedHead((WorkingCopyGitEventInfo) info);
                }
            }
        }

        @Override
        public void operationFailed(GitEventInfo info, Throwable t) {
            final GitOperation operation = info.getGitOperation();
            if (operation == GitOperation.CONTINUE_REBASE || operation == GitOperation.RESET_TO_COMMIT) {
                gitRefreshSupport.call();
            }
        }
    });
    gitRefreshSupport.call();
    viewInfo.setIcon(Icons.getIcon(Icons.GIT_ICON));
    viewInfo.setTitle(translator.getTranslation(Tags.GIT_STAGING));
}
Also used : NoRepositorySelected(com.oxygenxml.git.service.NoRepositorySelected) GitEventInfo(com.oxygenxml.git.view.event.GitEventInfo) WorkingCopyGitEventInfo(com.oxygenxml.git.view.event.WorkingCopyGitEventInfo) GitOperation(com.oxygenxml.git.view.event.GitOperation) GitEventAdapter(com.oxygenxml.git.service.GitEventAdapter) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel)

Example 2 with StagingPanel

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

the class BranchSelectionComboTest method testKeepCurrentBranchSelectedWhenSwitchFails.

/**
 * <p><b>Description:</b> when trying to switch to another branch from the branches menu
 * and the checkout fails, keep the previous branch selected.</p>
 * <p><b>Bug ID:</b> EXM-46826</p>
 *
 * @author sorin_carbunaru
 *
 * @throws Exception
 */
public void testKeepCurrentBranchSelectedWhenSwitchFails() throws Exception {
    File testDir = new File(String.format("target/test-resources/ToolbarPanelTest/%s", this.getName()));
    String local = String.format("target/test-resources/ToolbarPanelTest/%s/localRepository", this.getName());
    String remote = String.format("target/test-resources/ToolbarPanelTest/%s/remoteRepository", this.getName());
    String LOCAL_BRANCH = "LocalBranch";
    // Creates the remote repository.
    createRepo(remote, local);
    // Make the first commit for the local repository
    File file = new File(local, "local.txt");
    file.createNewFile();
    setFileContent(file, "local content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
    gitAccess.commit("First local commit.");
    // Make the first commit for the remote repository and create a branch for it.
    gitAccess.setRepositorySynchronously(remote);
    file = new File(remote, "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    // Switch back to local repo and create local branch
    gitAccess.setRepositorySynchronously(local);
    gitAccess.createBranch(LOCAL_BRANCH);
    gitAccess.fetch();
    JFrame frame = new JFrame();
    try {
        // Init UI
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        JComboBox<String> wcCombo = stagingPanel.getWorkingCopySelectionPanel().getWorkingCopyCombo();
        String wcPath = new File(local).getAbsolutePath();
        wcCombo.addItem(wcPath);
        wcCombo.setSelectedItem(wcPath);
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        refreshSupport.call();
        flushAWT();
        // Commit a change
        file = new File(local, "local.txt");
        setFileContent(file, "new 2");
        gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
        gitAccess.commit("First remote commit.");
        flushAWT();
        // Create local change
        setFileContent(file, "new 3");
        refreshSupport.call();
        flushAWT();
        // Try to switch to another branch
        BranchSelectionCombo branchesCombo = stagingPanel.getBranchesCombo();
        branchesCombo.refresh();
        String currentBranch = (String) branchesCombo.getSelectedItem();
        assertEquals("main", currentBranch);
        // select the "Local Branch" (aka the broken one)
        branchesCombo.setSelectedIndex(0);
        // wait for swith dialog to appear
        JDialog switchBranchDialog = TestUtil.waitForDialog(translator.getTranslation(Tags.SWITCH_BRANCH), this);
        JButton yesButton = TestUtil.findButton(switchBranchDialog, translator.getTranslation(Tags.MOVE_CHANGES));
        yesButton.doClick();
        flushAWT();
        String currentBranchAfterSwitchFailed = (String) branchesCombo.getSelectedItem();
        assertEquals("main", currentBranchAfterSwitchFailed);
    } finally {
        frame.setVisible(false);
        frame.dispose();
        FileSystemUtil.deleteRecursivelly(testDir);
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) BranchSelectionCombo(com.oxygenxml.git.view.staging.BranchSelectionCombo) JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) JDialog(javax.swing.JDialog) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 3 with StagingPanel

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

the class BranchSelectionComboTest method testCanStashChangesIfSwitchBranchFailsBecauseUncommitedFiles.

/**
 * <p><b>Description:</b> when trying to switch to another branch from the branches menu
 * and the checkout fails, tests the dialog</p>
 * <p><b>Bug ID:</b> EXM-48502</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testCanStashChangesIfSwitchBranchFailsBecauseUncommitedFiles() throws Exception {
    File testDir = new File(String.format("target/test-resources/ToolbarPanelTest/%s", this.getName()));
    String local = String.format("target/test-resources/ToolbarPanelTest/%s/localRepository", this.getName());
    String remote = String.format("target/test-resources/ToolbarPanelTest/%s/remoteRepository", this.getName());
    String LOCAL_BRANCH = "LocalBranch";
    // Creates the remote repository.
    createRepo(remote, local);
    // Make the first commit for the local repository
    File file = new File(local, "local.txt");
    file.createNewFile();
    setFileContent(file, "local content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
    gitAccess.commit("First local commit.");
    // Make the first commit for the remote repository and create a branch for it.
    gitAccess.setRepositorySynchronously(remote);
    file = new File(remote, "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    // Switch back to local repo and create local branch
    gitAccess.setRepositorySynchronously(local);
    gitAccess.createBranch(LOCAL_BRANCH);
    gitAccess.fetch();
    JFrame frame = new JFrame();
    try {
        // Init UI
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        JComboBox<String> wcCombo = stagingPanel.getWorkingCopySelectionPanel().getWorkingCopyCombo();
        String wcPath = new File(local).getAbsolutePath();
        wcCombo.addItem(wcPath);
        wcCombo.setSelectedItem(wcPath);
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        refreshSupport.call();
        flushAWT();
        // Commit a change
        file = new File(local, "local.txt");
        setFileContent(file, "new 2");
        gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
        gitAccess.commit("First remote commit.");
        flushAWT();
        // Create local change
        setFileContent(file, "new 3");
        refreshSupport.call();
        flushAWT();
        // Try to switch to another branch
        BranchSelectionCombo branchesCombo = stagingPanel.getBranchesCombo();
        branchesCombo.refresh();
        flushAWT();
        String currentBranch = (String) branchesCombo.getSelectedItem();
        assertEquals("main", currentBranch);
        // select other branch
        branchesCombo.setSelectedIndex(0);
        JDialog switchBranchDialog = TestUtil.waitForDialog(translator.getTranslation(Tags.SWITCH_BRANCH), this);
        JButton stashButton = TestUtil.findButton(switchBranchDialog, Tags.STASH_CHANGES);
        stashButton.doClick();
        flushAWT();
        StashChangesDialog stashChangesDialog = (StashChangesDialog) findDialog(Tags.STASH_CHANGES);
        assertNotNull(stashChangesDialog);
        stashChangesDialog.setVisible(false);
        stashChangesDialog.dispose();
    } finally {
        frame.setVisible(false);
        frame.dispose();
        FileSystemUtil.deleteRecursivelly(testDir);
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) BranchSelectionCombo(com.oxygenxml.git.view.staging.BranchSelectionCombo) JFrame(javax.swing.JFrame) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) StashChangesDialog(com.oxygenxml.git.view.stash.StashChangesDialog) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) JDialog(javax.swing.JDialog) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 4 with StagingPanel

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

the class RemoteVisualTests method testTrackRemoteBranch.

/**
 * <p><b>Description:</b> Tests the "Track remote branch" action from remote button of git staging toolbar.</p>
 * <p><b>Bug ID:</b> EXM-40858</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testTrackRemoteBranch() throws Exception {
    final String remoteRepo2Branch = "branch_remote_repo_2";
    final String remote2 = "remote2_name";
    // Creates the remote repository.
    createRepository(REMOTE_REPO2);
    Repository remoteRepository = gitAccess.getRepository();
    addRemote(localRepository, remoteRepository, remote2);
    gitAccess.createBranch(remoteRepo2Branch);
    File file = new File(REMOTE_REPO2, "remote2.txt");
    file.createNewFile();
    setFileContent(file, "remote2content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote2.txt"));
    gitAccess.commit("First remote2 commit.");
    // Make the first commit for the local repository
    file = new File(LOCAL_REPO, "local.txt");
    file.createNewFile();
    setFileContent(file, "local content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
    gitAccess.commit("First local commit.");
    // Make the first commit for the remote repository and create a branch for it.
    gitAccess.setRepositorySynchronously(REMOTE_REPO);
    file = new File(REMOTE_REPO, "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    // Switch back to local repo and create local branch
    gitAccess.setRepositorySynchronously(LOCAL_REPO);
    gitAccess.createBranch(LOCAL_BRANCH);
    gitAccess.fetch();
    JFrame frame = new JFrame();
    try {
        // Init UI
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        flushAWT();
        refreshSupport.call();
        flushAWT();
        SwingUtilities.invokeLater(() -> gitActionsManager.getTrackRemoteBranchAction().actionPerformed(null));
        flushAWT();
        CurrentBranchRemotesDialog[] trackRemoteDialog = new CurrentBranchRemotesDialog[1];
        trackRemoteDialog[0] = (CurrentBranchRemotesDialog) findDialog(Tags.CONFIGURE_REMOTE_FOR_BRANCH);
        assertNotNull(trackRemoteDialog);
        flushAWT();
        JComboBox<RemoteBranchItem> remoteBranches = trackRemoteDialog[0].getRemoteBranchItems();
        assertNotNull(remoteBranches);
        assertEquals(2, remoteBranches.getItemCount());
        assertEquals("origin", gitAccess.getRemoteFromCurrentBranch());
        RemoteBranchItem currentSelected = (RemoteBranchItem) remoteBranches.getSelectedItem();
        assertEquals("origin/main", currentSelected.toString());
        remoteBranches.setSelectedIndex(1);
        currentSelected = (RemoteBranchItem) remoteBranches.getSelectedItem();
        assertEquals("remote2_name/main", currentSelected.toString());
        flushAWT();
        sleep(500);
        SwingUtilities.invokeLater(() -> trackRemoteDialog[0].getOkButton().doClick());
        // Test if the config file is updated after user confirmation.
        SwingUtilities.invokeLater(() -> gitActionsManager.getTrackRemoteBranchAction().actionPerformed(null));
        flushAWT();
        trackRemoteDialog[0] = (CurrentBranchRemotesDialog) findDialog(Tags.CONFIGURE_REMOTE_FOR_BRANCH);
        assertNotNull(trackRemoteDialog);
        flushAWT();
        remoteBranches = trackRemoteDialog[0].getRemoteBranchItems();
        assertNotNull(remoteBranches);
        assertEquals(remote2, gitAccess.getRemoteFromCurrentBranch());
        currentSelected = (RemoteBranchItem) remoteBranches.getSelectedItem();
        assertEquals("remote2_name/main", currentSelected.toString());
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : CurrentBranchRemotesDialog(com.oxygenxml.git.view.remotes.CurrentBranchRemotesDialog) Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) JFrame(javax.swing.JFrame) GitController(com.oxygenxml.git.view.event.GitController) File(java.io.File) RemoteBranchItem(com.oxygenxml.git.view.remotes.CurrentBranchRemotesDialog.RemoteBranchItem) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager)

Example 5 with StagingPanel

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

the class StashVisualTests method testListStashDeleteAction.

/**
 * <p><b>Description:</b> Tests the "List stashes" delete action</p>
 * <p><b>Bug ID:</b> EXM-45983</p>
 *
 * @author Alex_Smarandache
 *
 * @throws Exception
 */
public void testListStashDeleteAction() throws Exception {
    // Make the first commit for the local repository
    File file = new File(LOCAL_REPO, "local.txt");
    file.createNewFile();
    setFileContent(file, "local content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "local.txt"));
    gitAccess.commit("First local commit.");
    // Make the first commit for the remote repository
    gitAccess.setRepositorySynchronously(REMOTE_REPO);
    file = new File(REMOTE_REPO, "remote1.txt");
    file.createNewFile();
    setFileContent(file, "remote content");
    gitAccess.add(new FileStatus(GitChangeType.ADD, "remote1.txt"));
    gitAccess.commit("First remote commit.");
    // Switch back to local repo and create local branch
    gitAccess.setRepositorySynchronously(LOCAL_REPO);
    gitAccess.createBranch(LOCAL_BRANCH);
    gitAccess.fetch();
    JFrame frame = new JFrame();
    try {
        // Init UI
        GitController gitCtrl = new GitController();
        GitActionsManager gitActionsManager = new GitActionsManager(gitCtrl, null, null, refreshSupport);
        stagingPanel = new StagingPanel(refreshSupport, gitCtrl, null, gitActionsManager);
        ToolbarPanel toolbarPanel = stagingPanel.getToolbarPanel();
        frame.getContentPane().add(stagingPanel);
        frame.pack();
        frame.setVisible(true);
        flushAWT();
        toolbarPanel.updateButtonsStates();
        refreshSupport.call();
        flushAWT();
        SplitMenuButton stashButton = toolbarPanel.getStashButton();
        initStashes(toolbarPanel);
        List<RevCommit> stashes = new ArrayList<>(gitAccess.listStashes());
        assertEquals(3, stashes.size());
        JMenuItem[] listStashesItem = new JMenuItem[1];
        listStashesItem[0] = stashButton.getItem(1);
        SwingUtilities.invokeLater(() -> listStashesItem[0].getAction().actionPerformed(null));
        ListStashesDialog listStashesDialog = (ListStashesDialog) findDialog(Tags.STASHES);
        assertNotNull(listStashesDialog);
        assertEquals(3, listStashesDialog.getStashesTable().getModel().getRowCount());
        JButton[] deleteSelectedStashButton = new JButton[1];
        flushAWT();
        deleteSelectedStashButton[0] = findFirstButton(listStashesDialog, Tags.DELETE);
        assertNotNull(deleteSelectedStashButton);
        SwingUtilities.invokeLater(() -> deleteSelectedStashButton[0].doClick());
        flushAWT();
        // Test the no button.
        JDialog deleteSelectedStashDialog = findDialog(Tags.DELETE_STASH);
        assertNotNull(deleteSelectedStashDialog);
        JButton[] noButton = new JButton[1];
        flushAWT();
        noButton[0] = findFirstButton(deleteSelectedStashDialog, Tags.NO);
        assertNotNull(noButton[0]);
        SwingUtilities.invokeLater(() -> noButton[0].doClick());
        flushAWT();
        stashes = new ArrayList<>(gitAccess.listStashes());
        assertEquals(3, stashes.size());
        listStashesItem[0] = stashButton.getItem(1);
        SwingUtilities.invokeLater(() -> listStashesItem[0].getAction().actionPerformed(null));
        // Test the yes button.
        String[] stashesMessages = { "Stash1", "Stash0" };
        // Delete all stashes one by one
        for (int i = 0; i < 3; i++) {
            flushAWT();
            deleteSelectedStashButton[0] = findFirstButton(listStashesDialog, Tags.DELETE);
            assertNotNull(deleteSelectedStashButton);
            SwingUtilities.invokeLater(() -> deleteSelectedStashButton[0].doClick());
            flushAWT();
            deleteSelectedStashDialog = findDialog(Tags.DELETE_STASH);
            assertNotNull(deleteSelectedStashDialog);
            flushAWT();
            JButton yesButton = findFirstButton(deleteSelectedStashDialog, Tags.YES);
            assertNotNull(yesButton);
            SwingUtilities.invokeLater(yesButton::doClick);
            flushAWT();
            stashes = new ArrayList<>(gitAccess.listStashes());
            assertEquals(3 - i - 1, stashes.size());
            assertEquals(3 - i - 1, listStashesDialog.getStashesTable().getRowCount());
            int stashIndex = 0;
            for (int j = i + 1; j < 3; j++) {
                assertEquals(stashesMessages[i + stashIndex], stashes.get(stashIndex).getFullMessage());
                assertEquals(stashesMessages[i + stashIndex], listStashesDialog.getStashesTable().getValueAt(stashIndex++, 1));
            }
        }
        flushAWT();
        JButton cancelButton = findFirstButton(listStashesDialog, Tags.CLOSE);
        assertNotNull(cancelButton);
        cancelButton.doClick();
    } finally {
        frame.setVisible(false);
        frame.dispose();
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) SplitMenuButton(ro.sync.exml.workspace.api.standalone.ui.SplitMenuButton) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) GitController(com.oxygenxml.git.view.event.GitController) ListStashesDialog(com.oxygenxml.git.view.stash.ListStashesDialog) GitActionsManager(com.oxygenxml.git.view.actions.GitActionsManager) JFrame(javax.swing.JFrame) JMenuItem(javax.swing.JMenuItem) File(java.io.File) StagingPanel(com.oxygenxml.git.view.staging.StagingPanel) ToolbarPanel(com.oxygenxml.git.view.staging.ToolbarPanel) JDialog(javax.swing.JDialog) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

StagingPanel (com.oxygenxml.git.view.staging.StagingPanel)15 GitActionsManager (com.oxygenxml.git.view.actions.GitActionsManager)14 GitController (com.oxygenxml.git.view.event.GitController)14 JFrame (javax.swing.JFrame)13 File (java.io.File)10 JButton (javax.swing.JButton)10 FileStatus (com.oxygenxml.git.service.entities.FileStatus)9 JDialog (javax.swing.JDialog)8 ToolbarPanel (com.oxygenxml.git.view.staging.ToolbarPanel)7 JMenuItem (javax.swing.JMenuItem)6 SplitMenuButton (ro.sync.exml.workspace.api.standalone.ui.SplitMenuButton)6 ListStashesDialog (com.oxygenxml.git.view.stash.ListStashesDialog)5 ArrayList (java.util.ArrayList)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 JTextField (javax.swing.JTextField)3 RemotesRepositoryDialog (com.oxygenxml.git.view.remotes.RemotesRepositoryDialog)2 RemotesTableModel (com.oxygenxml.git.view.remotes.RemotesTableModel)2 BranchSelectionCombo (com.oxygenxml.git.view.staging.BranchSelectionCombo)2 JTable (javax.swing.JTable)2 Repository (org.eclipse.jgit.lib.Repository)2