Пример #1
0
  @Override
  protected boolean handleDelete(RequestInfo requestInfo) throws ServletException {

    HttpServletRequest request = requestInfo.request;
    HttpServletResponse response = requestInfo.response;
    Repository db = requestInfo.db;

    /* 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));
    }
  }
Пример #2
0
  @Override
  protected boolean handlePut(RequestInfo requestInfo) throws ServletException {

    JSONObject requestPayload = requestInfo.getJSONRequest();
    HttpServletRequest request = requestInfo.request;
    HttpServletResponse response = requestInfo.response;
    Repository db = requestInfo.db;

    /* 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));
    }
  }
Пример #3
0
 public static void stashDrop(final Git repo) throws GitAPIException {
   repo.stashDrop().call();
 }