Skip to content

Commit 3c954c2

Browse files
committed
Merge branch 'db/maint-missing-origin' into maint
* db/maint-missing-origin: Remove total confusion from git-fetch and git-push Give error when no remote is configured
2 parents 0e1aa2f + 9326d49 commit 3c954c2

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
@@ -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;
@@ -330,8 +331,10 @@ static int handle_config(const char *key, const char *value, void *cb)
330331
if (!value)
331332
return config_error_nonbool(key);
332333
branch->remote_name = xstrdup(value);
333-
if (branch == current_branch)
334+
if (branch == current_branch) {
334335
default_remote_name = branch->remote_name;
336+
explicit_default_remote_name = 1;
337+
}
335338
} else if (!strcmp(subkey, ".merge")) {
336339
if (!value)
337340
return config_error_nonbool(key);
@@ -643,18 +646,24 @@ static int valid_remote_nick(const char *name)
643646
struct remote *remote_get(const char *name)
644647
{
645648
struct remote *ret;
649+
int name_given = 0;
646650

647651
read_config();
648-
if (!name)
652+
if (name)
653+
name_given = 1;
654+
else {
649655
name = default_remote_name;
656+
name_given = explicit_default_remote_name;
657+
}
658+
650659
ret = make_remote(name, 0);
651660
if (valid_remote_nick(name)) {
652661
if (!ret->url)
653662
read_remotes_file(ret);
654663
if (!ret->url)
655664
read_branches_file(ret);
656665
}
657-
if (!ret->url)
666+
if (name_given && !ret->url)
658667
add_url_alias(ret, name);
659668
if (!ret->url)
660669
return NULL;

0 commit comments

Comments
 (0)