]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/t9001-send-email.sh
send-email: support validate hook
[thirdparty/git.git] / t / t9001-send-email.sh
index 60a80f60b2685c461f80cdbf4256eb17dc18b85b..15128c755a4eb820b9735e1a94616a694b1b8054 100755 (executable)
@@ -1913,4 +1913,44 @@ test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
        test_cmp expected-list actual-list
 '
 
+test_expect_success $PREREQ 'invoke hook' '
+       mkdir -p .git/hooks &&
+
+       write_script .git/hooks/sendemail-validate <<-\EOF &&
+       # test that we have the correct environment variable, pwd, and
+       # argument
+       case "$GIT_DIR" in
+       *.git)
+               true
+               ;;
+       *)
+               false
+               ;;
+       esac &&
+       test -f 0001-add-master.patch &&
+       grep "add master" "$1"
+       EOF
+
+       mkdir subdir &&
+       (
+               # Test that it works even if we are not at the root of the
+               # working tree
+               cd subdir &&
+               git send-email \
+                       --from="Example <nobody@example.com>" \
+                       --to=nobody@example.com \
+                       --smtp-server="$(pwd)/../fake.sendmail" \
+                       ../0001-add-master.patch &&
+
+               # Verify error message when a patch is rejected by the hook
+               sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
+               git send-email \
+                       --from="Example <nobody@example.com>" \
+                       --to=nobody@example.com \
+                       --smtp-server="$(pwd)/../fake.sendmail" \
+                       ../another.patch 2>err
+               test_i18ngrep "rejected by sendemail-validate hook" err
+       )
+'
+
 test_done