git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] branch: make sure the upstream remote is configured
@ 2013-07-26 17:39 Carlos Martín Nieto
  2013-07-26 18:43 ` Jeff King
  0 siblings, 1 reply; 6+ messages in thread
From: Carlos Martín Nieto @ 2013-07-26 17:39 UTC (permalink / raw)
  To: git

A command of e.g.

    git push --set-upstream /tmp/t master

will call install_branch_config() with a remote name of "/tmp/t". This
function will set the 'branch.master.remote' key to, which is
nonsensical as there is no remote by that name.

Instead, make sure that the remote given does exist when writing the
configuration and warn if it does not. In order to distinguish named
remotes, introduce REMOTE_NONE as the default origin for remotes,
which the functions reading from the different sources will
overwrite. Thus, an origin of REMOTE_NONE means it has been created at
run-time in order to push to it.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
---

It's somewhat surprising that there didn't seem to be a way to
distinguish named remotes from those created from a command-line path,
but I guess nobody needed to.

 branch.c                 | 11 +++++++++++
 remote.h                 |  1 +
 t/t5523-push-upstream.sh |  5 +++++
 3 files changed, 17 insertions(+)

diff --git a/branch.c b/branch.c
index c5c6984..cefb8f6 100644
--- a/branch.c
+++ b/branch.c
@@ -53,6 +53,7 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
 	int remote_is_branch = !prefixcmp(remote, "refs/heads/");
 	struct strbuf key = STRBUF_INIT;
 	int rebasing = should_setup_rebase(origin);
+	struct remote *r = remote_get(origin);
 
 	if (remote_is_branch
 	    && !strcmp(local, shortname)
@@ -62,6 +63,16 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
 		return;
 	}
 
+	/*
+	 * Make sure that the remote passed is a configured remote, or
+	 * we end up setting 'branch.foo.remote = /tmp/t' which is
+	 * nonsensical.
+	 */
+	if (origin && strcmp(origin, ".") && r->origin == REMOTE_NONE) {
+		warning(_("there is no remote named '%s', no upstream configuration will be set."), origin);
+		return;
+	}
+
 	strbuf_addf(&key, "branch.%s.remote", local);
 	git_config_set(key.buf, origin ? origin : ".");
 
diff --git a/remote.h b/remote.h
index cf56724..92f6e33 100644
--- a/remote.h
+++ b/remote.h
@@ -2,6 +2,7 @@
 #define REMOTE_H
 
 enum {
+	REMOTE_NONE,
 	REMOTE_CONFIG,
 	REMOTE_REMOTES,
 	REMOTE_BRANCHES
diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh
index 3683df1..e84c2f8 100755
--- a/t/t5523-push-upstream.sh
+++ b/t/t5523-push-upstream.sh
@@ -71,6 +71,11 @@ test_expect_success 'push -u HEAD' '
 	check_config headbranch upstream refs/heads/headbranch
 '
 
+test_expect_success 'push -u <url>' '
+        git push -u parent HEAD 2>err &&
+        grep "no upstream configuration will be set" err
+'
+
 test_expect_success TTY 'progress messages go to tty' '
 	ensure_fresh_upstream &&
 
-- 
1.8.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-07-26 23:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-26 17:39 [PATCH] branch: make sure the upstream remote is configured Carlos Martín Nieto
2013-07-26 18:43 ` Jeff King
2013-07-26 18:48   ` Jeff King
2013-07-26 22:29   ` Carlos Martín Nieto
2013-07-26 23:12     ` Jeff King
2013-07-26 23:22       ` Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).