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

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

Introduction

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

Prototype

@Override
public ObjectId call() throws GitAPIException 

Source Link

Document

Drop the configured entry from the stash reflog and return value of the stash reference after the drop occurs

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);/*w  ww.  jav  a 2  s. c om*/
            try {
                command.call();
                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 handlePut(RequestInfo requestInfo) throws ServletException {

    JSONObject requestPayload = requestInfo.getJSONRequest();
    HttpServletRequest request = requestInfo.request;
    HttpServletResponse response = requestInfo.response;
    Repository db = requestInfo.db;//from   w  w  w.  j a v a2s  .c o m

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

    boolean applyIndex = requestPayload.optBoolean(GitConstants.KEY_STASH_APPLY_INDEX, true);
    boolean applyUntracked = requestPayload.optBoolean(GitConstants.KEY_STASH_APPLY_UNTRACKED, true);

    try {

        Git git = new Git(db);

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

        StashApplyCommand applyCommand = new StashApplyCommand(db);

        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));
            }

            applyCommand.setStashRef(stashRef.getStringRef());
            applyCommand.setApplyUntracked(applyUntracked);
            applyCommand.setApplyIndex(applyIndex);
            applyCommand.call();

        } else {

            /* git stash pop */
            applyCommand.setApplyUntracked(applyUntracked);
            applyCommand.setApplyIndex(applyIndex);
            applyCommand.call();

            StashDropCommand dropCommand = git.stashDrop();
            dropCommand.setAll(false);
            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));
    }
}

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;/*from   w w w .  ja  v  a2  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));
    }
}