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
This commit is contained in:
Junio C Hamano 2009-03-17 18:58:41 -07:00
commit 9d5b05c6d5
3 changed files with 20 additions and 8 deletions

View File

@ -636,6 +636,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
else else
remote = remote_get(argv[0]); remote = remote_get(argv[0]);
if (!remote)
die("Where do you want to fetch from today?");
transport = transport_get(remote, remote->url[0]); transport = transport_get(remote, remote->url[0]);
if (verbosity >= 2) if (verbosity >= 2)
transport->verbose = 1; transport->verbose = 1;
@ -648,9 +651,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
if (depth) if (depth)
set_option(TRANS_OPT_DEPTH, depth); set_option(TRANS_OPT_DEPTH, depth);
if (!transport->url)
die("Where do you want to fetch from today?");
if (argc > 1) { if (argc > 1) {
int j = 0; int j = 0;
refs = xcalloc(argc + 1, sizeof(const char *)); refs = xcalloc(argc + 1, sizeof(const char *));

View File

@ -53,8 +53,11 @@ static int do_push(const char *repo, int flags)
int i, errs; int i, errs;
struct remote *remote = remote_get(repo); struct remote *remote = remote_get(repo);
if (!remote) if (!remote) {
die("bad repository '%s'", repo); if (repo)
die("bad repository '%s'", repo);
die("No destination configured to push to.");
}
if (remote->mirror) if (remote->mirror)
flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE); flags |= (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE);

View File

@ -39,6 +39,7 @@ static int branches_nr;
static struct branch *current_branch; static struct branch *current_branch;
static const char *default_remote_name; static const char *default_remote_name;
static int explicit_default_remote_name;
static struct rewrite **rewrite; static struct rewrite **rewrite;
static int rewrite_alloc; static int rewrite_alloc;
@ -331,8 +332,10 @@ static int handle_config(const char *key, const char *value, void *cb)
if (!value) if (!value)
return config_error_nonbool(key); return config_error_nonbool(key);
branch->remote_name = xstrdup(value); branch->remote_name = xstrdup(value);
if (branch == current_branch) if (branch == current_branch) {
default_remote_name = branch->remote_name; default_remote_name = branch->remote_name;
explicit_default_remote_name = 1;
}
} else if (!strcmp(subkey, ".merge")) { } else if (!strcmp(subkey, ".merge")) {
if (!value) if (!value)
return config_error_nonbool(key); return config_error_nonbool(key);
@ -644,10 +647,16 @@ static int valid_remote_nick(const char *name)
struct remote *remote_get(const char *name) struct remote *remote_get(const char *name)
{ {
struct remote *ret; struct remote *ret;
int name_given = 0;
read_config(); read_config();
if (!name) if (name)
name_given = 1;
else {
name = default_remote_name; name = default_remote_name;
name_given = explicit_default_remote_name;
}
ret = make_remote(name, 0); ret = make_remote(name, 0);
if (valid_remote_nick(name)) { if (valid_remote_nick(name)) {
if (!ret->url) if (!ret->url)
@ -655,7 +664,7 @@ struct remote *remote_get(const char *name)
if (!ret->url) if (!ret->url)
read_branches_file(ret); read_branches_file(ret);
} }
if (!ret->url) if (name_given && !ret->url)
add_url_alias(ret, name); add_url_alias(ret, name);
if (!ret->url) if (!ret->url)
return NULL; return NULL;