PreReceiveHook.java

  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. package org.eclipse.jgit.transport;

  11. import java.util.Collection;

  12. /**
  13.  * Hook invoked by {@link org.eclipse.jgit.transport.ReceivePack} before any
  14.  * updates are executed.
  15.  * <p>
  16.  * The hook is called with any commands that are deemed valid after parsing them
  17.  * from the client and applying the standard receive configuration options to
  18.  * them:
  19.  * <ul>
  20.  * <li><code>receive.denyDenyDeletes</code></li>
  21.  * <li><code>receive.denyNonFastForwards</code></li>
  22.  * </ul>
  23.  * This means the hook will not receive a non-fast-forward update command if
  24.  * denyNonFastForwards is set to true in the configuration file. To get all
  25.  * commands within the hook, see
  26.  * {@link org.eclipse.jgit.transport.ReceivePack#getAllCommands()}.
  27.  * <p>
  28.  * As the hook is invoked prior to the commands being executed, the hook may
  29.  * choose to block any command by setting its result status with
  30.  * {@link org.eclipse.jgit.transport.ReceiveCommand#setResult(ReceiveCommand.Result)}.
  31.  * <p>
  32.  * The hook may also choose to perform the command itself (or merely pretend
  33.  * that it has performed the command), by setting the result status to
  34.  * {@link org.eclipse.jgit.transport.ReceiveCommand.Result#OK}.
  35.  * <p>
  36.  * Hooks should run quickly, as they block the caller thread and the client
  37.  * process from completing.
  38.  * <p>
  39.  * Hooks may send optional messages back to the client via methods on
  40.  * {@link org.eclipse.jgit.transport.ReceivePack}. Implementors should be aware
  41.  * that not all network transports support this output, so some (or all)
  42.  * messages may simply be discarded. These messages should be advisory only.
  43.  */
  44. public interface PreReceiveHook {
  45.     /** A simple no-op hook. */
  46.     PreReceiveHook NULL = (final ReceivePack rp,
  47.             final Collection<ReceiveCommand> commands) -> {
  48.         // Do nothing.
  49.     };

  50.     /**
  51.      * Invoked just before commands are executed.
  52.      * <p>
  53.      * See the class description for how this method can impact execution.
  54.      *
  55.      * @param rp
  56.      *            the process handling the current receive. Hooks may obtain
  57.      *            details about the destination repository through this handle.
  58.      * @param commands
  59.      *            unmodifiable set of valid commands still pending execution.
  60.      *            May be the empty set.
  61.      */
  62.     void onPreReceive(ReceivePack rp, Collection<ReceiveCommand> commands);
  63. }