View Javadoc
1   /*
2    * Copyright (C) 2008, Google Inc. 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  
11  package org.eclipse.jgit.transport;
12  
13  import java.util.Collection;
14  
15  /**
16   * Hook invoked by {@link org.eclipse.jgit.transport.ReceivePack} before any
17   * updates are executed.
18   * <p>
19   * The hook is called with any commands that are deemed valid after parsing them
20   * from the client and applying the standard receive configuration options to
21   * them:
22   * <ul>
23   * <li><code>receive.denyDenyDeletes</code></li>
24   * <li><code>receive.denyNonFastForwards</code></li>
25   * </ul>
26   * This means the hook will not receive a non-fast-forward update command if
27   * denyNonFastForwards is set to true in the configuration file. To get all
28   * commands within the hook, see
29   * {@link org.eclipse.jgit.transport.ReceivePack#getAllCommands()}.
30   * <p>
31   * As the hook is invoked prior to the commands being executed, the hook may
32   * choose to block any command by setting its result status with
33   * {@link org.eclipse.jgit.transport.ReceiveCommand#setResult(ReceiveCommand.Result)}.
34   * <p>
35   * The hook may also choose to perform the command itself (or merely pretend
36   * that it has performed the command), by setting the result status to
37   * {@link org.eclipse.jgit.transport.ReceiveCommand.Result#OK}.
38   * <p>
39   * Hooks should run quickly, as they block the caller thread and the client
40   * process from completing.
41   * <p>
42   * Hooks may send optional messages back to the client via methods on
43   * {@link org.eclipse.jgit.transport.ReceivePack}. Implementors should be aware
44   * that not all network transports support this output, so some (or all)
45   * messages may simply be discarded. These messages should be advisory only.
46   */
47  public interface PreReceiveHook {
48  	/** A simple no-op hook. */
49  	PreReceiveHook NULL = (final ReceivePack rp,
50  			final Collection<ReceiveCommand> commands) -> {
51  		// Do nothing.
52  	};
53  
54  	/**
55  	 * Invoked just before commands are executed.
56  	 * <p>
57  	 * See the class description for how this method can impact execution.
58  	 *
59  	 * @param rp
60  	 *            the process handling the current receive. Hooks may obtain
61  	 *            details about the destination repository through this handle.
62  	 * @param commands
63  	 *            unmodifiable set of valid commands still pending execution.
64  	 *            May be the empty set.
65  	 */
66  	void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands);
67  }