git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/3] push: Add support for pre-push hooks

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 15, 2013, 00:36 UTC
Message-ID
<7vip6z7056.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1358054224-7710-3-git-send-email-aaron@schrab.com>
Aaron Schrab <aaron@schrab.com> writes:
Show 19 quoted lines
>  t/t5571-pre-push-hook.sh   | 129 +++++++++++++++++++++++++++++++++++++++++++++
> diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh
> new file mode 100755
> index 0000000..d68fed7
> --- /dev/null
> +++ b/t/t5571-pre-push-hook.sh
> @@ -0,0 +1,129 @@
> +#!/bin/sh
> +
> +test_description='check pre-push hooks'
> +. ./test-lib.sh
> +
> +# Setup hook that always succeeds
> +HOOKDIR="$(git rev-parse --git-dir)/hooks"
> +HOOK="$HOOKDIR/pre-push"
> +mkdir -p "$HOOKDIR"
> +write_script "$HOOK" <<EOF
> +exit 0
> +EOF

As this script is expected to read from the pipe, if this exits before the parent has a chance to write to the pipe, the parent can be killed with sigpipe.

At least the attached patch is necessary.

In the longer term, we may want to discuss what should happen when the hook exited without even reading what we fed. My gut feeling is that we can still trust its exit status (a hook that was badly coded so it wanted to read from us and use that information to decide but somehow died before fully reading from us is not likely to exit with zero status, so we wouldn't diagnosing breakage as a success), but there may be downsides for being that lax.

If we decide we want to be lax, then the call site of this hook and the pre-receive hook (is there any other "take info from the standard input" hook?) need to be modified so that they ignore sigpipe, I think.

There was a related discussion around this issue about a year ago.
http://thread.gmane.org/gmane.comp.version-control.git/180346/focus=186291
 t/t5571-pre-push-hook.sh | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh
index d68fed7..577d252 100755
--- a/t/t5571-pre-push-hook.sh
+++ b/t/t5571-pre-push-hook.sh
@@ -8,6 +8,7 @@ HOOKDIR="$(git rev-parse --git-dir)/hooks"
 HOOK="$HOOKDIR/pre-push"
 mkdir -p "$HOOKDIR"
 write_script "$HOOK" <<EOF
+cat >/dev/null
 exit 0
 EOF
 
@@ -19,6 +20,7 @@ test_expect_success 'setup' '
 	git push parent1 HEAD:foreign
 '
 write_script "$HOOK" <<EOF
+cat >/dev/null
 exit 1
 EOF
 
@@ -38,6 +40,7 @@ COMMIT2="$(git rev-parse HEAD)"
 export COMMIT2
 
 write_script "$HOOK" <<'EOF'
+cat >/dev/null
 echo "$1" >actual
 echo "$2" >>actual
 cat >>actual
Previous: Junio C HamanoNext: Junio C Hamano
Message 16 of 22 in “pre-push hook support”
  1. 0/4 pre-push hook supportAaron Schrab, Dec 28, 2012
  2. 1/4 hooks: Add function to check if a hook existsAaron Schrab, Dec 28, 2012
  3. Junio C HamanoDec 29, 2012
  4. Aaron SchrabDec 29, 2012
  5. Junio C HamanoDec 29, 2012
  6. 2/4 hooks: support variable number of parametersAaron Schrab, Dec 28, 2012
  7. 3/4 push: Add support for pre-push hooksAaron Schrab, Dec 28, 2012
  8. 4/4 Add sample pre-push hook scriptAaron Schrab, Dec 28, 2012
  9. Junio C HamanoDec 29, 2012
  10. Aaron SchrabDec 29, 2012
  11. Junio C HamanoDec 29, 2012
  12. 0/3 pre-push hook supportAaron Schrab, Jan 13, 2013
  13. 1/3 hooks: Add function to check if a hook existsAaron Schrab, Jan 13, 2013
  14. 2/3 push: Add support for pre-push hooksAaron Schrab, Jan 13, 2013
  15. Junio C HamanoJan 14, 2013
  16. Junio C HamanoJan 15, 2013
  17. Junio C HamanoJan 15, 2013
  18. 3/3 Add sample pre-push hook scriptAaron Schrab, Jan 13, 2013
  19. Junio C HamanoJan 14, 2013
  20. Junio C HamanoJan 14, 2013
  21. Junio C HamanoJan 14, 2013
  22. Junio C HamanoJan 15, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.