You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PostCommitHook.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. import java.io.IOException;
  12. import java.io.PrintStream;
  13. import org.eclipse.jgit.api.errors.AbortedByHookException;
  14. import org.eclipse.jgit.lib.Repository;
  15. import org.eclipse.jgit.util.ProcessResult;
  16. /**
  17. * The <code>post-commit</code> hook implementation. This hook is run after the
  18. * commit was successfully executed.
  19. *
  20. * @since 4.5
  21. */
  22. public class PostCommitHook extends GitHook<Void> {
  23. /** The post-commit hook name. */
  24. public static final String NAME = "post-commit"; //$NON-NLS-1$
  25. /**
  26. * Constructor for PostCommitHook
  27. * <p>
  28. * This constructor will use the default error stream.
  29. * </p>
  30. *
  31. * @param repo
  32. * The repository
  33. * @param outputStream
  34. * The output stream the hook must use. {@code null} is allowed,
  35. * in which case the hook will use {@code System.out}.
  36. */
  37. protected PostCommitHook(Repository repo, PrintStream outputStream) {
  38. super(repo, outputStream);
  39. }
  40. /**
  41. * Constructor for PostCommitHook
  42. *
  43. * @param repo
  44. * The repository
  45. * @param outputStream
  46. * The output stream the hook must use. {@code null} is allowed,
  47. * in which case the hook will use {@code System.out}.
  48. * @param errorStream
  49. * The error stream the hook must use. {@code null} is allowed,
  50. * in which case the hook will use {@code System.err}.
  51. * @since 5.6
  52. */
  53. protected PostCommitHook(Repository repo, PrintStream outputStream,
  54. PrintStream errorStream) {
  55. super(repo, outputStream, errorStream);
  56. }
  57. /** {@inheritDoc} */
  58. @Override
  59. public Void call() throws IOException, AbortedByHookException {
  60. doRun();
  61. return null;
  62. }
  63. /** {@inheritDoc} */
  64. @Override
  65. public String getHookName() {
  66. return NAME;
  67. }
  68. /**
  69. * Overwrites the default implementation to never throw an
  70. * {@link AbortedByHookException}, as the commit has already been done and
  71. * the exit code of the post-commit hook has no effect.
  72. */
  73. @Override
  74. protected void handleError(String message, ProcessResult result)
  75. throws AbortedByHookException {
  76. // Do nothing as the exit code of the post-commit hook has no effect.
  77. }
  78. }