Merge branch 'jc/fsck-dropped-errors' into maint
[gitweb.git] / builtin / push.c
index 57c138bd7bc972bfa337de4c615cbfffb99ecc71..3bda430b6b1cf455986afae537ee8429dae5a001 100644 (file)
@@ -9,6 +9,7 @@
 #include "transport.h"
 #include "parse-options.h"
 #include "submodule.h"
+#include "send-pack.h"
 
 static const char * const push_usage[] = {
        N_("git push [<options>] [<repository> [<refspec>...]]"),
@@ -471,6 +472,24 @@ static int option_parse_recurse_submodules(const struct option *opt,
        return 0;
 }
 
+static void set_push_cert_flags(int *flags, int v)
+{
+       switch (v) {
+       case SEND_PACK_PUSH_CERT_NEVER:
+               *flags &= ~(TRANSPORT_PUSH_CERT_ALWAYS | TRANSPORT_PUSH_CERT_IF_ASKED);
+               break;
+       case SEND_PACK_PUSH_CERT_ALWAYS:
+               *flags |= TRANSPORT_PUSH_CERT_ALWAYS;
+               *flags &= ~TRANSPORT_PUSH_CERT_IF_ASKED;
+               break;
+       case SEND_PACK_PUSH_CERT_IF_ASKED:
+               *flags |= TRANSPORT_PUSH_CERT_IF_ASKED;
+               *flags &= ~TRANSPORT_PUSH_CERT_ALWAYS;
+               break;
+       }
+}
+
+
 static int git_push_config(const char *k, const char *v, void *cb)
 {
        int *flags = cb;
@@ -486,6 +505,23 @@ static int git_push_config(const char *k, const char *v, void *cb)
                else
                        *flags &= ~TRANSPORT_PUSH_FOLLOW_TAGS;
                return 0;
+       } else if (!strcmp(k, "push.gpgsign")) {
+               const char *value;
+               if (!git_config_get_value("push.gpgsign", &value)) {
+                       switch (git_config_maybe_bool("push.gpgsign", value)) {
+                       case 0:
+                               set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_NEVER);
+                               break;
+                       case 1:
+                               set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_ALWAYS);
+                               break;
+                       default:
+                               if (value && !strcasecmp(value, "if-asked"))
+                                       set_push_cert_flags(flags, SEND_PACK_PUSH_CERT_IF_ASKED);
+                               else
+                                       return error("Invalid value for '%s'", k);
+                       }
+               }
        }
 
        return git_default_config(k, v, NULL);
@@ -495,6 +531,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 {
        int flags = 0;
        int tags = 0;
+       int push_cert = -1;
        int rc;
        const char *repo = NULL;        /* default repository */
        struct option options[] = {
@@ -526,7 +563,9 @@ int cmd_push(int argc, const char **argv, const char *prefix)
                OPT_BIT(0, "no-verify", &flags, N_("bypass pre-push hook"), TRANSPORT_PUSH_NO_HOOK),
                OPT_BIT(0, "follow-tags", &flags, N_("push missing but relevant tags"),
                        TRANSPORT_PUSH_FOLLOW_TAGS),
-               OPT_BIT(0, "signed", &flags, N_("GPG sign the push"), TRANSPORT_PUSH_CERT),
+               { OPTION_CALLBACK,
+                 0, "signed", &push_cert, "yes|no|if-asked", N_("GPG sign the push"),
+                 PARSE_OPT_OPTARG, option_parse_push_signed },
                OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC),
                OPT_END()
        };
@@ -534,6 +573,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
        packet_trace_identity("push");
        git_config(git_push_config, &flags);
        argc = parse_options(argc, argv, prefix, options, push_usage, 0);
+       set_push_cert_flags(&flags, push_cert);
 
        if (deleterefs && (tags || (flags & (TRANSPORT_PUSH_ALL | TRANSPORT_PUSH_MIRROR))))
                die(_("--delete is incompatible with --all, --mirror and --tags"));