Skip to content

Commit fa685bd

Browse files
iabervongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9a6682b commit fa685bd

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

builtin-fetch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
636636
else
637637
remote = remote_get(argv[0]);
638638

639+
if (!remote)
640+
die("Where do you want to fetch from today?");
641+
639642
transport = transport_get(remote, remote->url[0]);
640643
if (verbosity >= 2)
641644
transport->verbose = 1;
@@ -648,9 +651,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
648651
if (depth)
649652
set_option(TRANS_OPT_DEPTH, depth);
650653

651-
if (!transport->url)
652-
die("Where do you want to fetch from today?");
653-
654654
if (argc > 1) {
655655
int j = 0;
656656
refs = xcalloc(argc + 1, sizeof(const char *));

builtin-push.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ static int do_push(const char *repo, int flags)
5353
int i, errs;
5454
struct remote *remote = remote_get(repo);
5555

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+
}
5861

5962
if (remote->mirror)
6063
flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);

remote.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static int branches_nr;
3838

3939
static struct branch *current_branch;
4040
static const char *default_remote_name;
41+
static int explicit_default_remote_name;
4142

4243
static struct rewrite **rewrite;
4344
static int rewrite_alloc;
@@ -104,6 +105,16 @@ static void add_url_alias(struct remote *remote, const char *url)
104105
add_url(remote, alias_url(url));
105106
}
106107

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+
107118
static struct remote *make_remote(const char *name, int len)
108119
{
109120
struct remote *ret;
@@ -330,8 +341,10 @@ static int handle_config(const char *key, const char *value, void *cb)
330341
if (!value)
331342
return config_error_nonbool(key);
332343
branch->remote_name = xstrdup(value);
333-
if (branch == current_branch)
344+
if (branch == current_branch) {
334345
default_remote_name = branch->remote_name;
346+
explicit_default_remote_name = 1;
347+
}
335348
} else if (!strcmp(subkey, ".merge")) {
336349
if (!value)
337350
return config_error_nonbool(key);
@@ -643,11 +656,22 @@ static int valid_remote_nick(const char *name)
643656
struct remote *remote_get(const char *name)
644657
{
645658
struct remote *ret;
659+
int name_given = 0;
646660

647661
read_config();
648-
if (!name)
662+
if (name)
663+
name_given = 1;
664+
else {
649665
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+
}
651675
if (valid_remote_nick(name)) {
652676
if (!ret->url)
653677
read_remotes_file(ret);

0 commit comments

Comments
 (0)