Merge branch 'jc/push-default-explicit'
authorJunio C Hamano <gitster@pobox.com>
Tue, 27 Dec 2016 08:11:40 +0000 (00:11 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Dec 2016 08:11:40 +0000 (00:11 -0800)
A lazy "git push" without refspec did not internally use a fully
specified refspec to perform 'current', 'simple', or 'upstream'
push, causing unnecessary "ambiguous ref" errors.

* jc/push-default-explicit:
push: test pushing ambiguously named branches
push: do not use potentially ambiguous default refspec

1  2 
builtin/push.c
diff --combined builtin/push.c
index 3bb9d6b7e63b3e3082023c3d333c11757df6fbda,00a1b684830c0201361b9ec84d874aaa40b2a9e0..9307ad56a9fb91455eaf06371382b1431d115598
@@@ -194,15 -194,18 +194,18 @@@ static void setup_push_upstream(struct 
                        die_push_simple(branch, remote);
        }
  
-       strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src);
+       strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src);
        add_refspec(refspec.buf);
  }
  
  static void setup_push_current(struct remote *remote, struct branch *branch)
  {
+       struct strbuf refspec = STRBUF_INIT;
        if (!branch)
                die(_(message_detached_head_die), remote->name);
-       add_refspec(branch->name);
+       strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname);
+       add_refspec(refspec.buf);
  }
  
  static int is_workflow_triangular(struct remote *remote)
@@@ -353,8 -356,7 +356,8 @@@ static int push_with_options(struct tra
        return 1;
  }
  
 -static int do_push(const char *repo, int flags)
 +static int do_push(const char *repo, int flags,
 +                 const struct string_list *push_options)
  {
        int i, errs;
        struct remote *remote = pushremote_get(repo);
        if (remote->mirror)
                flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
  
 +      if (push_options->nr)
 +              flags |= TRANSPORT_PUSH_OPTIONS;
 +
        if ((flags & TRANSPORT_PUSH_ALL) && refspec) {
                if (!strcmp(*refspec, "refs/tags/*"))
                        return error(_("--all and --tags are incompatible"));
                for (i = 0; i < url_nr; i++) {
                        struct transport *transport =
                                transport_get(remote, url[i]);
 +                      if (flags & TRANSPORT_PUSH_OPTIONS)
 +                              transport->push_options = push_options;
                        if (push_with_options(transport, flags))
                                errs++;
                }
        } else {
                struct transport *transport =
                        transport_get(remote, NULL);
 -
 +              if (flags & TRANSPORT_PUSH_OPTIONS)
 +                      transport->push_options = push_options;
                if (push_with_options(transport, flags))
                        errs++;
        }
@@@ -507,9 -503,6 +510,9 @@@ int cmd_push(int argc, const char **arg
        int push_cert = -1;
        int rc;
        const char *repo = NULL;        /* default repository */
 +      static struct string_list push_options = STRING_LIST_INIT_DUP;
 +      static struct string_list_item *item;
 +
        struct option options[] = {
                OPT__VERBOSITY(&verbosity),
                OPT_STRING( 0 , "repo", &repo, N_("repository"), N_("repository")),
                  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_STRING_LIST('o', "push-option", &push_options, N_("server-specific"), N_("option to transmit")),
                OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"),
                                TRANSPORT_FAMILY_IPV4),
                OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"),
                set_refspecs(argv + 1, argc - 1, repo);
        }
  
 -      rc = do_push(repo, flags);
 +      for_each_string_list_item(item, &push_options)
 +              if (strchr(item->string, '\n'))
 +                      die(_("push options must not have new line characters"));
 +
 +      rc = do_push(repo, flags, &push_options);
        if (rc == -1)
                usage_with_options(push_usage, options);
        else