summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-04-20 22:49:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-04-20 22:49:51 (GMT)
commit27da1cf65b9f30a51c061409c697f94b9b56b09c (patch)
treeeca16ddaa3ff9a7d8efd23453bdc274be13e2696 /builtin
parentbb52e7f600c9732c624ffc27f8321f55c4b4d90b (diff)
parent135dadef712f0c4cf884940e751024c831937904 (diff)
downloadgit-27da1cf65b9f30a51c061409c697f94b9b56b09c.zip
git-27da1cf65b9f30a51c061409c697f94b9b56b09c.tar.gz
git-27da1cf65b9f30a51c061409c697f94b9b56b09c.tar.bz2
Merge branch 'jc/push-upstream-sanity'
Fix broken 'push to upstream' implementation. "git push $there" without refspec, when the current branch is set to push to a remote different from $there, used to push to $there using the upstream information to a remote unreleated to $there. * jc/push-upstream-sanity: push: error out when the "upstream" semantics does not make sense
Diffstat (limited to 'builtin')
-rw-r--r--builtin/push.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/builtin/push.c b/builtin/push.c
index d315475..b6c0fee 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -65,6 +65,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;
@@ -76,7 +86,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"
@@ -87,6 +97,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);
}
@@ -196,13 +212,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 =