aboutsummaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorDaniel Barkalow <barkalow@iabervon.org>2009-03-11 01:47:20 -0400
committerJunio C Hamano <gitster@pobox.com>2009-03-10 23:14:20 -0700
commitfa685bdf45cbaa997255cc78a23494b995e9769a (patch)
tree9d9105e85bc7477e6a4c93091c511f3191d22b60 /remote.c
parent9a6682bab5e800465f0a4e44cdf18fe396ff4f6d (diff)
downloadgit-fa685bdf45cbaa997255cc78a23494b995e9769a.tar.gz
git-fa685bdf45cbaa997255cc78a23494b995e9769a.tar.xz
Give error when no remote is configured
When there's no explicitly-named remote, we use the remote specified for the current branch, which in turn defaults to "origin". But it this case should require the remote to actually be configured, and not fall back to the path "origin". Possibly, the config file's "remote = something" should require the something to be a configured remote instead of a bare repository URL, but we actually test with a bare repository URL. In fetch, we were giving the sensible error message when coming up with a URL failed, but this wasn't actually reachable, so move that error up and use it when appropriate. In push, we need a new error message, because the old one (formerly unreachable without a lot of help) used the repo name, which was NULL. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/remote.c b/remote.c
index d7079c6dd..199830ea9 100644
--- a/remote.c
+++ b/remote.c
@@ -38,6 +38,7 @@ static int branches_nr;
static struct branch *current_branch;
static const char *default_remote_name;
+static int explicit_default_remote_name;
static struct rewrite **rewrite;
static int rewrite_alloc;
@@ -104,6 +105,16 @@ static void add_url_alias(struct remote *remote, const char *url)
add_url(remote, alias_url(url));
}
+static struct remote *get_remote_by_name(const char *name)
+{
+ int i;
+ for (i = 0; i < remotes_nr; i++) {
+ if (!strcmp(name, remotes[i]->name))
+ return remotes[i];
+ }
+ return NULL;
+}
+
static struct remote *make_remote(const char *name, int len)
{
struct remote *ret;
@@ -330,8 +341,10 @@ static int handle_config(const char *key, const char *value, void *cb)
if (!value)
return config_error_nonbool(key);
branch->remote_name = xstrdup(value);
- if (branch == current_branch)
+ if (branch == current_branch) {
default_remote_name = branch->remote_name;
+ explicit_default_remote_name = 1;
+ }
} else if (!strcmp(subkey, ".merge")) {
if (!value)
return config_error_nonbool(key);
@@ -643,11 +656,22 @@ static int valid_remote_nick(const char *name)
struct remote *remote_get(const char *name)
{
struct remote *ret;
+ int name_given = 0;
read_config();
- if (!name)
+ if (name)
+ name_given = 1;
+ else {
name = default_remote_name;
- ret = make_remote(name, 0);
+ name_given = explicit_default_remote_name;
+ }
+ if (name_given)
+ ret = make_remote(name, 0);
+ else {
+ ret = get_remote_by_name(name);
+ if (!ret)
+ return NULL;
+ }
if (valid_remote_nick(name)) {
if (!ret->url)
read_remotes_file(ret);