/** Adds {@code stash@{x}} parameter to the handler, quotes it if needed. */
 private void addStashParameter(@NotNull GitHandler handler, @NotNull String stash) {
   if (GitVersionSpecialty.NEEDS_QUOTES_IN_STASH_NAME.existsIn(myVcs.getVersion())) {
     handler.addParameters("\"" + stash + "\"");
     handler.dontEscapeQuotes();
   } else {
     handler.addParameters(stash);
   }
 }
 private void commonOnSuccess(final Object LOCK, final GitTaskResultHandler resultHandler) {
   GitTaskResult res = !myHandler.errors().isEmpty() ? GitTaskResult.GIT_ERROR : GitTaskResult.OK;
   resultHandler.run(res);
   synchronized (LOCK) {
     LOCK.notifyAll();
   }
 }
  private void addListeners(final TaskExecution task, final ProgressIndicator indicator) {
    if (indicator != null) {
      indicator.setIndeterminate(myProgressAnalyzer == null);
    }
    // When receives an error line, adds a VcsException to the GitHandler.
    final GitLineHandlerListener listener =
        new GitLineHandlerListener() {
          @Override
          public void processTerminated(int exitCode) {
            if (exitCode != 0 && !myHandler.isIgnoredErrorCode(exitCode)) {
              if (myHandler.errors().isEmpty()) {
                myHandler.addError(new VcsException(myHandler.getLastOutput()));
              }
            }
          }

          @Override
          public void startFailed(Throwable exception) {
            myHandler.addError(
                new VcsException("Git start failed: " + exception.getMessage(), exception));
          }

          @Override
          public void onLineAvailable(String line, Key outputType) {
            if (GitHandlerUtil.isErrorLine(line.trim())) {
              myHandler.addError(new VcsException(line));
            } else if (!StringUtil.isEmptyOrSpaces(line)) {
              myHandler.addLastOutput(line);
            }
            if (indicator != null) {
              indicator.setText2(line);
            }
            if (myProgressAnalyzer != null && indicator != null) {
              final double fraction = myProgressAnalyzer.analyzeProgress(line);
              if (fraction >= 0) {
                indicator.setFraction(fraction);
              }
            }
          }
        };

    if (myHandler instanceof GitLineHandler) {
      ((GitLineHandler) myHandler).addLineListener(listener);
    } else {
      myHandler.addListener(listener);
    }

    // disposes the timer
    myHandler.addListener(
        new GitHandlerListener() {
          @Override
          public void processTerminated(int exitCode) {
            task.dispose();
          }

          @Override
          public void startFailed(Throwable exception) {
            task.dispose();
          }
        });
  }