From: Jacob Keller Date: Wed, 9 Apr 2014 22:26:05 +0000 (-0700) Subject: aiaiai-email-test-patchset: correct hook calling to actually grab error X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f491665839e8b033d4e20cfe2ea1c66609f2adde;p=users%2Fdedekind%2Faiaiai.git aiaiai-email-test-patchset: correct hook calling to actually grab error We can't grab the $? value from inside an if block, as the if statement already changed the return code. Instead, we just call the hook script without an error section, and then check for errors afterwards. This corrects an issue where the return code would always be 0, even if the command failed. Signed-off-by: Jacob Keller Signed-off-by: Artem Bityutskiy --- diff --git a/email/aiaiai-email-test-patchset b/email/aiaiai-email-test-patchset index 0376957..af5f18b 100755 --- a/email/aiaiai-email-test-patchset +++ b/email/aiaiai-email-test-patchset @@ -288,19 +288,23 @@ hookscript="$(readlink -ev -- $cfg_email_hook)" if [ -f "$hookscript" ] && [ -x "$hookscript" ]; then # Hook points to an executable file, so we run it verbose "Executing \"$hookscript\"" - if ! "$hookscript" "$cfgfile" "$mbox" > "$hookoutput"; then - hookret=$? - - # Error code 127 is an expected output of the hook, and - # indicates that we should reject this patch. The reply email - # will be sent to the user, and the hook is expected to have - # outputted the rejection indication. As a precaution, the - # rejection email will include a list of projects supported. - if [ "$hookret" -eq "127" ]; then - error_hook_rejected_patch < "$hookoutput" - else - error_internal_error_occurred - fi + + # Grab the error code here, using an || section to prevent exit on + # command failure. Otherwise, the non-zero exit code from the hook + # script would crash aiaiai-email-test-patchset + hookret="0" + "$hookscript" "$cfgfile" "$mbox" > "$hookoutput" || hookret="$?" + + # Error code 127 is an expected output of the hook, and + # indicates that we should reject this patch. The reply email + # will be sent to the user, and the hook is expected to have + # outputted the rejection indication. As a precaution, the + # rejection email will include a list of projects supported. + if [ "$hookret" -eq "127" ]; then + error_hook_rejected_patch < "$hookoutput" + elif [ "$hookret" -ne "0" ]; then + verbose "Hook exited with error code \"$hookret\"..." + error_internal_error_occurred fi fi