View Javadoc
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.hooks;
11  
12  import java.io.IOException;
13  import java.io.PrintStream;
14  
15  import org.eclipse.jgit.api.errors.AbortedByHookException;
16  import org.eclipse.jgit.lib.Repository;
17  
18  /**
19   * The <code>pre-commit</code> hook implementation. This hook is run before the
20   * commit and can reject the commit.
21   *
22   * @since 4.0
23   */
24  public class PreCommitHook extends GitHook<Void> {
25  
26  	/** The pre-commit hook name. */
27  	public static final String NAME = "pre-commit"; //$NON-NLS-1$
28  
29  	/**
30  	 * Constructor for PreCommitHook
31  	 * <p>
32  	 * This constructor will use the default error stream.
33  	 * </p>
34  	 *
35  	 * @param repo
36  	 *            The repository
37  	 * @param outputStream
38  	 *            The output stream the hook must use. {@code null} is allowed,
39  	 *            in which case the hook will use {@code System.out}.
40  	 */
41  	protected PreCommitHook(Repository repo, PrintStream outputStream) {
42  		super(repo, outputStream);
43  	}
44  
45  	/**
46  	 * Constructor for PreCommitHook
47  	 *
48  	 * @param repo
49  	 *            The repository
50  	 * @param outputStream
51  	 *            The output stream the hook must use. {@code null} is allowed,
52  	 *            in which case the hook will use {@code System.out}.
53  	 * @param errorStream
54  	 *            The error stream the hook must use. {@code null} is allowed,
55  	 *            in which case the hook will use {@code System.err}.
56  	 * @since 5.6
57  	 */
58  	protected PreCommitHook(Repository repo, PrintStream outputStream,
59  			PrintStream errorStream) {
60  		super(repo, outputStream, errorStream);
61  	}
62  
63  	/** {@inheritDoc} */
64  	@Override
65  	public Void call() throws IOException, AbortedByHookException {
66  		doRun();
67  		return null;
68  	}
69  
70  	/** {@inheritDoc} */
71  	@Override
72  	public String getHookName() {
73  		return NAME;
74  	}
75  
76  }