Merge branch 'maint'
[gitweb.git] / builtin / push.c
index 8a14e4bcc12bc3ee2741fb1077f6513cd9eba99f..19c40d7a55199984d7cdc1efbacfca7b628a4d20 100644 (file)
@@ -66,6 +66,16 @@ static void set_refspecs(const char **refs, int nr)
        }
 }
 
+static int push_url_of_remote(struct remote *remote, const char ***url_p)
+{
+       if (remote->pushurl_nr) {
+               *url_p = remote->pushurl;
+               return remote->pushurl_nr;
+       }
+       *url_p = remote->url;
+       return remote->url_nr;
+}
+
 static void setup_push_upstream(struct remote *remote)
 {
        struct strbuf refspec = STRBUF_INIT;
@@ -77,7 +87,7 @@ static void setup_push_upstream(struct remote *remote)
                    "\n"
                    "    git push %s HEAD:<name-of-remote-branch>\n"),
                    remote->name);
-       if (!branch->merge_nr || !branch->merge)
+       if (!branch->merge_nr || !branch->merge || !branch->remote_name)
                die(_("The current branch %s has no upstream branch.\n"
                    "To push the current branch and set the remote as upstream, use\n"
                    "\n"
@@ -88,6 +98,12 @@ static void setup_push_upstream(struct remote *remote)
        if (branch->merge_nr != 1)
                die(_("The current branch %s has multiple upstream branches, "
                    "refusing to push."), branch->name);
+       if (strcmp(branch->remote_name, remote->name))
+               die(_("You are pushing to remote '%s', which is not the upstream of\n"
+                     "your current branch '%s', without telling me what to push\n"
+                     "to update which remote branch."),
+                   remote->name, branch->name);
+
        strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src);
        add_refspec(refspec.buf);
 }
@@ -246,13 +262,7 @@ static int do_push(const char *repo, int flags)
                        setup_default_push_refspecs(remote);
        }
        errs = 0;
-       if (remote->pushurl_nr) {
-               url = remote->pushurl;
-               url_nr = remote->pushurl_nr;
-       } else {
-               url = remote->url;
-               url_nr = remote->url_nr;
-       }
+       url_nr = push_url_of_remote(remote, &url);
        if (url_nr) {
                for (i = 0; i < url_nr; i++) {
                        struct transport *transport =
@@ -274,13 +284,21 @@ static int option_parse_recurse_submodules(const struct option *opt,
                                   const char *arg, int unset)
 {
        int *flags = opt->value;
+
+       if (*flags & (TRANSPORT_RECURSE_SUBMODULES_CHECK |
+                     TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND))
+               die("%s can only be used once.", opt->long_name);
+
        if (arg) {
                if (!strcmp(arg, "check"))
                        *flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK;
+               else if (!strcmp(arg, "on-demand"))
+                       *flags |= TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND;
                else
                        die("bad %s argument: %s", opt->long_name, arg);
        } else
-               die("option %s needs an argument (check)", opt->long_name);
+               die("option %s needs an argument (check|on-demand)",
+                               opt->long_name);
 
        return 0;
 }