Example usage for org.eclipse.jgit.api StashDropCommand setStashRef

List of usage examples for org.eclipse.jgit.api StashDropCommand setStashRef

Introduction

In this page you can find the example usage for org.eclipse.jgit.api StashDropCommand setStashRef.

Prototype

public StashDropCommand setStashRef(int stashRef) 

Source Link

Document

Set the stash reference to drop (0-based).

Usage

From source file:org.eclipse.egit.core.op.StashDropOperation.java

License:Open Source License

public void execute(IProgressMonitor monitor) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        public void run(IProgressMonitor pm) throws CoreException {
            pm.beginTask("", 1); //$NON-NLS-1$
            StashDropCommand command = Git.wrap(repo).stashDrop();
            command.setStashRef(index);
            try {
                command.call();//from   ww w  . jav a 2  s. co  m
                repo.fireEvent(new RefsChangedEvent());
            } catch (JGitInternalException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } catch (GitAPIException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } finally {
                pm.done();
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, monitor != null ? monitor : new NullProgressMonitor());
}

From source file:org.eclipse.orion.server.git.servlets.GitStashHandlerV1.java

License:Open Source License

@Override
protected boolean handleDelete(RequestInfo requestInfo) throws ServletException {

    HttpServletRequest request = requestInfo.request;
    HttpServletResponse response = requestInfo.response;
    Repository db = requestInfo.db;/*  w  ww  . j a va 2 s .  c  o m*/

    /* gitapi/stash/<stashRev>/file/(...) */
    String stashRev = requestInfo.gitSegment;

    try {

        Git git = new Git(db);

        /* check for empty stash */
        if (isStashEmpty(git)) {
            String msg = "Failed to drop stashed changes due to an empty stash.";
            return statusHandler.handleRequest(request, response,
                    new ServerStatus(IStatus.WARNING, HttpServletResponse.SC_BAD_REQUEST, msg, null));
        }

        StashDropCommand dropCommand = git.stashDrop();

        if (stashRev != null) {

            StashRef stashRef = getStashRef(git, stashRev);
            if (stashRef == null) {
                String msg = NLS.bind("Invalid stash reference {0}.", stashRev);
                return statusHandler.handleRequest(request, response,
                        new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, msg, null));
            }

            dropCommand.setStashRef(stashRef.getRef());

        } else
            dropCommand.setAll(true);

        dropCommand.call();
        return true;

    } catch (Exception ex) {
        String msg = "An error occured for stash command.";
        return statusHandler.handleRequest(request, response,
                new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, ex));
    }
}