Skip to content

Commit 9d5b05c

Browse files
committed
Merge branch 'db/maint-missing-origin'
* db/maint-missing-origin: Remove total confusion from git-fetch and git-push Give error when no remote is configured
2 parents 6e5660a + 9326d49 commit 9d5b05c

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-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: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static int branches_nr;
3939

4040
static struct branch *current_branch;
4141
static const char *default_remote_name;
42+
static int explicit_default_remote_name;
4243

4344
static struct rewrite **rewrite;
4445
static int rewrite_alloc;
@@ -331,8 +332,10 @@ static int handle_config(const char *key, const char *value, void *cb)
331332
if (!value)
332333
return config_error_nonbool(key);
333334
branch->remote_name = xstrdup(value);
334-
if (branch == current_branch)
335+
if (branch == current_branch) {
335336
default_remote_name = branch->remote_name;
337+
explicit_default_remote_name = 1;
338+
}
336339
} else if (!strcmp(subkey, ".merge")) {
337340
if (!value)
338341
return config_error_nonbool(key);
@@ -644,18 +647,24 @@ static int valid_remote_nick(const char *name)
644647
struct remote *remote_get(const char *name)
645648
{
646649
struct remote *ret;
650+
int name_given = 0;
647651

648652
read_config();
649-
if (!name)
653+
if (name)
654+
name_given = 1;
655+
else {
650656
name = default_remote_name;
657+
name_given = explicit_default_remote_name;
658+
}
659+
651660
ret = make_remote(name, 0);
652661
if (valid_remote_nick(name)) {
653662
if (!ret->url)
654663
read_remotes_file(ret);
655664
if (!ret->url)
656665
read_branches_file(ret);
657666
}
658-
if (!ret->url)
667+
if (name_given && !ret->url)
659668
add_url_alias(ret, name);
660669
if (!ret->url)
661670
return NULL;

0 commit comments

Comments
 (0)