When a server supports hook options, we send it options for quiet and
force if the user used push --force/--quiet.

Signed-off-by: Dennis Kaarsemaker <[email protected]>
---
 send-pack.c                  | 10 ++++++++++
 t/t5544-push-hook-options.sh | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100755 t/t5544-push-hook-options.sh

diff --git a/send-pack.c b/send-pack.c
index 047bd18..5630327 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -371,6 +371,8 @@ int send_pack(struct send_pack_args *args,
        int agent_supported = 0;
        int use_atomic = 0;
        int atomic_supported = 0;
+       int hook_options_supported = 0;
+       int hook_options_seen = 0;
        unsigned cmds_sent = 0;
        int ret;
        struct async demux;
@@ -393,6 +395,8 @@ int send_pack(struct send_pack_args *args,
                args->use_thin_pack = 0;
        if (server_supports("atomic"))
                atomic_supported = 1;
+       if (server_supports("hook-options"))
+               hook_options_supported = 1;
 
        if (args->push_cert != SEND_PACK_PUSH_CERT_NEVER) {
                int len;
@@ -429,6 +433,12 @@ int send_pack(struct send_pack_args *args,
                strbuf_addstr(&cap_buf, " atomic");
        if (agent_supported)
                strbuf_addf(&cap_buf, " agent=%s", git_user_agent_sanitized());
+       if (hook_options_supported) {
+               if (args->quiet)
+                       strbuf_addf(&cap_buf, "%squiet", hook_options_seen++ ? 
"," : " hook-options=");
+               if (args->force_update)
+                       strbuf_addf(&cap_buf, "%sforce", hook_options_seen++ ? 
"," : " hook-options=");
+       }
 
        /*
         * NEEDSWORK: why does delete-refs have to be so specific to
diff --git a/t/t5544-push-hook-options.sh b/t/t5544-push-hook-options.sh
new file mode 100755
index 0000000..6d52ad1
--- /dev/null
+++ b/t/t5544-push-hook-options.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+test_description='pushing to a repository with hook options'
+
+. ./test-lib.sh
+
+test_expect_success 'hook options are passed on to hooks' '
+       git init --bare remote.git &&
+       write_script remote.git/hooks/post-receive <<-\EOF &&
+       echo "post-receive-hook"
+       echo $GIT_HOOK_OPTIONS
+       EOF
+       (
+               test_commit one &&
+               git push remote/ master:test 2> actual &&
+               test_commit two &&
+               git push --quiet remote/ master:test 2>> actual &&
+               test_commit three &&
+               git push --force remote/ master:test 2>> actual &&
+               test_commit four &&
+               git push --quiet --force remote/ master:test 2>> actual
+       ) &&
+       sed -ne "s/remote: \([^ ]*\).*/\1/p" -i actual &&
+       cat > expected <<-\EOF &&
+       post-receive-hook
+
+       post-receive-hook
+       quiet
+       post-receive-hook
+       force
+       post-receive-hook
+       quiet,force
+       EOF
+       test_cmp expected actual
+'
+
+test_done
-- 
2.7.0-91-gf04ef09

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to