Search in sources :

Example 21 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method resetAll.

/**
 * Reset all the specified files from the staging area.
 *
 * @param files The list of file to be removed
 */
public void resetAll(List<FileStatus> files) {
    Collection<String> filePaths = getFilePaths(files);
    try {
        fireOperationAboutToStart(new FileGitEventInfo(GitOperation.UNSTAGE, filePaths));
        if (!files.isEmpty()) {
            ResetCommand reset = git.reset();
            for (FileStatus file : files) {
                reset.addPath(file.getFileLocation());
            }
            reset.call();
        }
        fireOperationSuccessfullyEnded(new FileGitEventInfo(GitOperation.UNSTAGE, filePaths));
    } catch (GitAPIException e) {
        fireOperationFailed(new FileGitEventInfo(GitOperation.UNSTAGE, filePaths), e);
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) FileStatus(com.oxygenxml.git.service.entities.FileStatus) ResetCommand(org.eclipse.jgit.api.ResetCommand) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo)

Example 22 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class ProjectMenuGitActionsProvider method getStagedAndUnstagedFiles.

/**
 * @return The staged and the unstaged files.
 */
private List<FileStatus> getStagedAndUnstagedFiles() {
    List<FileStatus> gitFiles = new ArrayList<>();
    GitStatus status = GitAccess.getInstance().getStatus();
    gitFiles.addAll(status.getUnstagedFiles());
    gitFiles.addAll(status.getStagedFiles());
    return gitFiles;
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) ArrayList(java.util.ArrayList) GitStatus(com.oxygenxml.git.service.GitStatus)

Example 23 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class ProjectMenuGitActionsProvider method doGitDiff.

/**
 * Do Git Diff.
 */
private void doGitDiff() {
    try {
        UIUtil.setBusyCursor(true, Arrays.asList(prjViewInfo));
        File selFile = pluginWS.getProjectManager().getSelectedFiles()[0];
        String repository = RepoUtil.getRepositoryForFile(selFile);
        if (repository != null) {
            try {
                RepoUtil.updateCurrentRepository(repository);
                List<FileStatus> gitFiles = getStagedAndUnstagedFiles();
                boolean wasDiffShown = false;
                if (!gitFiles.isEmpty()) {
                    String selectedFilePath = FileUtil.rewriteSeparator(selFile.getAbsolutePath());
                    for (FileStatus fileStatus : gitFiles) {
                        if (selectedFilePath.endsWith(fileStatus.getFileLocation())) {
                            SwingUtilities.invokeLater(() -> DiffPresenter.showDiff(fileStatus, gitCtrl));
                            wasDiffShown = true;
                            break;
                        }
                    }
                }
                if (!wasDiffShown) {
                    SwingUtilities.invokeLater(() -> pluginWS.showInformationMessage(translator.getTranslation(Tags.NO_CHANGES)));
                }
            } catch (Exception e1) {
                PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Repository opening failed due to: " + e1.getMessage());
                LOGGER.error(e1.getMessage(), e1);
            }
        }
    } finally {
        UIUtil.setBusyCursor(false, Arrays.asList(prjViewInfo));
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) File(java.io.File) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 24 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class ProjectMenuGitActionsProvider method doPrepareCommit.

/**
 * Prepare commit.
 */
private void doPrepareCommit() {
    try {
        UIUtil.setBusyCursor(true, Arrays.asList(prjViewInfo));
        File[] selectedFiles = pluginWS.getProjectManager().getSelectedFiles();
        String repository = RepoUtil.getRepositoryForFile(selectedFiles[0]);
        if (repository != null) {
            try {
                RepoUtil.updateCurrentRepository(repository);
                List<FileStatus> gitFiles = getStagedAndUnstagedFiles();
                boolean canCommit = false;
                for (File selFile : selectedFiles) {
                    String selectedFilePath = FileUtil.rewriteSeparator(selFile.getAbsolutePath());
                    for (FileStatus fileStatus : gitFiles) {
                        if (selectedFilePath.endsWith(fileStatus.getFileLocation())) {
                            canCommit = true;
                            break;
                        }
                    }
                }
                if (canCommit) {
                    SwingUtilities.invokeLater(() -> pluginWS.showView(OxygenGitPluginExtension.GIT_STAGING_VIEW, true));
                    stageFiles(repository);
                } else {
                    SwingUtilities.invokeLater(() -> pluginWS.showInformationMessage(translator.getTranslation(Tags.NOTHING_TO_COMMIT)));
                }
            } catch (IOException e1) {
                PluginWorkspaceProvider.getPluginWorkspace().showErrorMessage("Repository opening failed due to: " + e1.getMessage());
                LOGGER.error(e1.getMessage(), e1);
            }
        }
    } finally {
        UIUtil.setBusyCursor(false, Arrays.asList(prjViewInfo));
    }
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) IOException(java.io.IOException) File(java.io.File)

Example 25 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus 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)

Aggregations

FileStatus (com.oxygenxml.git.service.entities.FileStatus)210 File (java.io.File)136 Test (org.junit.Test)77 ArrayList (java.util.ArrayList)58 GitController (com.oxygenxml.git.view.event.GitController)53 List (java.util.List)50 Repository (org.eclipse.jgit.lib.Repository)49 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)38 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)33 JButton (javax.swing.JButton)33 SelectedResourcesProvider (com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider)26 IOException (java.io.IOException)25 AbstractAction (javax.swing.AbstractAction)24 JDialog (javax.swing.JDialog)24 GitResourceContextualMenu (com.oxygenxml.git.view.staging.GitResourceContextualMenu)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 URL (java.net.URL)18 Action (javax.swing.Action)18 CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)16