Search in sources :

Example 1 with CleanCommand

use of org.eclipse.jgit.api.CleanCommand in project egit by eclipse.

the class CleanRepositoryPage method updateCleanItems.

private void updateCleanItems() {
    try {
        getContainer().run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(UIText.CleanRepositoryPage_findingItems, IProgressMonitor.UNKNOWN);
                Git git = Git.wrap(repository);
                CleanCommand command = git.clean().setDryRun(true);
                command.setCleanDirectories(cleanDirectories);
                command.setIgnore(!includeIgnored);
                try {
                    final Set<String> paths = command.call();
                    getShell().getDisplay().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            cleanTable.setInput(paths);
                        }
                    });
                } catch (GitAPIException ex) {
                    // $NON-NLS-1$
                    Activator.logError("cannot call clean command!", ex);
                }
                monitor.done();
            }
        });
        updatePageComplete();
    } catch (InvocationTargetException e) {
        // $NON-NLS-1$
        Activator.logError("Unexpected exception while finding items to clean", e);
        clearPage();
    } catch (InterruptedException e) {
        clearPage();
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Git(org.eclipse.jgit.api.Git) CleanCommand(org.eclipse.jgit.api.CleanCommand) TreeSet(java.util.TreeSet) Set(java.util.Set) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 2 with CleanCommand

use of org.eclipse.jgit.api.CleanCommand in project egit by eclipse.

the class CleanRepositoryPage method finish.

/**
 * Do the cleaning with the selected values.
 */
public void finish() {
    try {
        final Set<String> itemsToClean = getItemsToClean();
        getContainer().run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                SubMonitor subMonitor = SubMonitor.convert(monitor, UIText.CleanRepositoryPage_cleaningItems, 1);
                Git git = Git.wrap(repository);
                CleanCommand command = git.clean().setDryRun(false);
                command.setCleanDirectories(cleanDirectories);
                command.setIgnore(!includeIgnored);
                command.setPaths(itemsToClean);
                try {
                    command.call();
                } catch (GitAPIException ex) {
                    // $NON-NLS-1$
                    Activator.logError("cannot call clean command!", ex);
                }
                try {
                    IProject[] projects = ProjectUtil.getProjectsContaining(repository, itemsToClean);
                    ProjectUtil.refreshResources(projects, subMonitor.newChild(1));
                } catch (CoreException e) {
                // could not refresh... not a "real" problem
                }
            }
        });
    } catch (Exception e) {
        // $NON-NLS-1$
        Activator.logError("Unexpected exception while cleaning", e);
    }
}
Also used : CleanCommand(org.eclipse.jgit.api.CleanCommand) SubMonitor(org.eclipse.core.runtime.SubMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Git(org.eclipse.jgit.api.Git) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with CleanCommand

use of org.eclipse.jgit.api.CleanCommand in project winery by eclipse.

the class GitBasedRepository method clean.

private void clean() throws NoWorkTreeException, GitAPIException {
    // remove untracked files
    try (Git git = getGit()) {
        CleanCommand clean = git.clean();
        clean.setCleanDirectories(true);
        clean.call();
    } catch (IOException e) {
        LOGGER.error("Error initializing Git.", e);
    }
}
Also used : Git(org.eclipse.jgit.api.Git) CleanCommand(org.eclipse.jgit.api.CleanCommand) IOException(java.io.IOException)

Example 4 with CleanCommand

use of org.eclipse.jgit.api.CleanCommand in project archi-modelrepository-plugin by archi-contribs.

the class ArchiRepository method resetToRef.

@Override
public void resetToRef(String ref) throws IOException, GitAPIException {
    // Check lock file is deleted
    checkDeleteLockFile();
    try (Git git = Git.open(getLocalRepositoryFolder())) {
        // Reset to master
        ResetCommand resetCommand = git.reset();
        resetCommand.setRef(ref);
        resetCommand.setMode(ResetType.HARD);
        resetCommand.call();
        // Clean extra files
        CleanCommand cleanCommand = git.clean();
        cleanCommand.setCleanDirectories(true);
        cleanCommand.call();
    }
}
Also used : Git(org.eclipse.jgit.api.Git) CleanCommand(org.eclipse.jgit.api.CleanCommand) ResetCommand(org.eclipse.jgit.api.ResetCommand)

Aggregations

CleanCommand (org.eclipse.jgit.api.CleanCommand)4 Git (org.eclipse.jgit.api.Git)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 IOException (java.io.IOException)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 CoreException (org.eclipse.core.runtime.CoreException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 ResetCommand (org.eclipse.jgit.api.ResetCommand)1