@matheusbsbs / matheus-bagliano / commits / fa685bdf45
Fork 0

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>

Daniel Barkalow committed Mar 11, 2009 at 01:47 UTC fa685bdf45cbaa997255cc78a23494b995e9769a
3 files changed +35 -8
builtin-fetch.c
+3 -3
@@ -636,6 +636,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
636 else
637 remote = remote_get(argv[0]);
638
639 + if (!remote)
640 + die("Where do you want to fetch from today?");
641 +
642 transport = transport_get(remote, remote->url[0]);
643 if (verbosity >= 2)
644 transport->verbose = 1;
@@ -648,9 +651,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
651 if (depth)
652 set_option(TRANS_OPT_DEPTH, depth);
653
651 - if (!transport->url)
652 - die("Where do you want to fetch from today?");
653 -
654 if (argc > 1) {
655 int j = 0;
656 refs = xcalloc(argc + 1, sizeof(const char *));
builtin-push.c
+5 -2
@@ -53,8 +53,11 @@ static int do_push(const char *repo, int flags)
53 int i, errs;
54 struct remote *remote = remote_get(repo);
55
56 - if (!remote)
57 - die("bad repository '%s'", repo);
56 + if (!remote) {
57 + if (repo)
58 + die("bad repository '%s'", repo);
59 + die("No destination configured to push to.");
60 + }
61
62 if (remote->mirror)
63 flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);
remote.c
+27 -3
@@ -38,6 +38,7 @@ static int branches_nr;
38
39 static struct branch *current_branch;
40 static const char *default_remote_name;
41 +static int explicit_default_remote_name;
42
43 static struct rewrite **rewrite;
44 static int rewrite_alloc;
@@ -104,6 +105,16 @@ static void add_url_alias(struct remote *remote, const char *url)
105 add_url(remote, alias_url(url));
106 }
107
108 +static struct remote *get_remote_by_name(const char *name)
109 +{
110 + int i;
111 + for (i = 0; i < remotes_nr; i++) {
112 + if (!strcmp(name, remotes[i]->name))
113 + return remotes[i];
114 + }
115 + return NULL;
116 +}
117 +
118 static struct remote *make_remote(const char *name, int len)
119 {
120 struct remote *ret;
@@ -330,8 +341,10 @@ static int handle_config(const char *key, const char *value, void *cb)
341 if (!value)
342 return config_error_nonbool(key);
343 branch->remote_name = xstrdup(value);
333 - if (branch == current_branch)
344 + if (branch == current_branch) {
345 default_remote_name = branch->remote_name;
346 + explicit_default_remote_name = 1;
347 + }
348 } else if (!strcmp(subkey, ".merge")) {
349 if (!value)
350 return config_error_nonbool(key);
@@ -643,11 +656,22 @@ static int valid_remote_nick(const char *name)
656 struct remote *remote_get(const char *name)
657 {
658 struct remote *ret;
659 + int name_given = 0;
660
661 read_config();
648 - if (!name)
662 + if (name)
663 + name_given = 1;
664 + else {
665 name = default_remote_name;
650 - ret = make_remote(name, 0);
666 + name_given = explicit_default_remote_name;
667 + }
668 + if (name_given)
669 + ret = make_remote(name, 0);
670 + else {
671 + ret = get_remote_by_name(name);
672 + if (!ret)
673 + return NULL;
674 + }
675 if (valid_remote_nick(name)) {
676 if (!ret->url)
677 read_remotes_file(ret);