AbortedByHookException.java

  1. /*
  2.  * Copyright (C) 2015 Obeo. and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */
  10. package org.eclipse.jgit.api.errors;

  11. import java.text.MessageFormat;

  12. import org.eclipse.jgit.internal.JGitText;

  13. /**
  14.  * Exception thrown when a hook returns a process result with a value different
  15.  * from 0. It is up to the caller to decide whether this should block execution
  16.  * or not.
  17.  *
  18.  * @since 4.0
  19.  */
  20. public class AbortedByHookException extends GitAPIException {
  21.     private static final long serialVersionUID = 1L;

  22.     /**
  23.      * The hook that caused this exception.
  24.      */
  25.     private final String hookName;

  26.     /**
  27.      * The process result.
  28.      */
  29.     private final int returnCode;

  30.     /**
  31.      * The stderr output of the hook.
  32.      */
  33.     private final String hookStdErr;

  34.     /**
  35.      * Constructor for AbortedByHookException
  36.      *
  37.      * @param hookStdErr
  38.      *            The error details from the stderr output of the hook
  39.      * @param hookName
  40.      *            The name of the hook that interrupted the command, must not be
  41.      *            null.
  42.      * @param returnCode
  43.      *            The return code of the hook process that has been run.
  44.      */
  45.     public AbortedByHookException(String hookStdErr, String hookName,
  46.             int returnCode) {
  47.         super(MessageFormat.format(JGitText.get().commandRejectedByHook,
  48.                 hookName, hookStdErr));
  49.         this.hookStdErr = hookStdErr;
  50.         this.hookName = hookName;
  51.         this.returnCode = returnCode;
  52.     }

  53.     /**
  54.      * Get hook name
  55.      *
  56.      * @return the type of the hook that interrupted the git command.
  57.      */
  58.     public String getHookName() {
  59.         return hookName;
  60.     }

  61.     /**
  62.      * Get return code
  63.      *
  64.      * @return the hook process result.
  65.      */
  66.     public int getReturnCode() {
  67.         return returnCode;
  68.     }

  69.     /**
  70.      * Get the stderr output of the hook.
  71.      *
  72.      * @return A string containing the complete stderr output of the hook.
  73.      * @since 5.6
  74.      */
  75.     public String getHookStdErr() {
  76.         return hookStdErr;
  77.     }
  78. }