From: "Carlos Martín Nieto" <cmn@elego.de>
To: git@vger.kernel.org
Subject: [PATCH] branch: make sure the upstream remote is configured
Date: Fri, 26 Jul 2013 19:39:37 +0200 [thread overview]
Message-ID: <1374860377-17652-1-git-send-email-cmn@elego.de> (raw)
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
next reply other threads:[~2013-07-26 17:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-26 17:39 Carlos Martín Nieto [this message]
2013-07-26 18:43 ` [PATCH] branch: make sure the upstream remote is configured 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374860377-17652-1-git-send-email-cmn@elego.de \
--to=cmn@elego.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).