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

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

Introduction

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

Prototype

public StashDropCommand setAll(boolean all) 

Source Link

Document

Set whether to drop all stashed commits

Usage

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  ww  . j  a va2  s .  com

    /* 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 ww  . ja v  a  2  s .co 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));
    }
}