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@xxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html