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
12 import java.text.MessageFormat;
13
14 import org.eclipse.jgit.internal.JGitText;
15
16 /**
17 * Exception thrown when a hook returns a process result with a value different
18 * from 0. It is up to the caller to decide whether this should block execution
19 * or not.
20 *
21 * @since 4.0
22 */
23 public class AbortedByHookException extends GitAPIException {
24 private static final long serialVersionUID = 1L;
25
26 /**
27 * The hook that caused this exception.
28 */
29 private final String hookName;
30
31 /**
32 * The process result.
33 */
34 private final int returnCode;
35
36 /**
37 * The stderr output of the hook.
38 */
39 private final String hookStdErr;
40
41 /**
42 * Constructor for AbortedByHookException
43 *
44 * @param hookStdErr
45 * The error details from the stderr output of the hook
46 * @param hookName
47 * The name of the hook that interrupted the command, must not be
48 * null.
49 * @param returnCode
50 * The return code of the hook process that has been run.
51 */
52 public AbortedByHookException(String hookStdErr, String hookName,
53 int returnCode) {
54 super(MessageFormat.format(JGitText.get().commandRejectedByHook,
55 hookName, hookStdErr));
56 this.hookStdErr = hookStdErr;
57 this.hookName = hookName;
58 this.returnCode = returnCode;
59 }
60
61 /**
62 * Get hook name
63 *
64 * @return the type of the hook that interrupted the git command.
65 */
66 public String getHookName() {
67 return hookName;
68 }
69
70 /**
71 * Get return code
72 *
73 * @return the hook process result.
74 */
75 public int getReturnCode() {
76 return returnCode;
77 }
78
79 /**
80 * Get the stderr output of the hook.
81 *
82 * @return A string containing the complete stderr output of the hook.
83 * @since 5.6
84 */
85 public String getHookStdErr() {
86 return hookStdErr;
87 }
88 }