branch: warn and refuse to set a branch as a tracking branch of itself.

Previous patch allows commands like "git branch --set-upstream foo foo",
which doesn't make much sense. Warn the user and don't change the
configuration in this case. Don't die to let the caller finish its job in
such case.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Matthieu Moy 2010-01-18 22:44:12 +02:00 коммит произвёл Junio C Hamano
Родитель 4fc5006676
Коммит 85e2233f98
1 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -49,9 +49,19 @@ static int should_setup_rebase(const char *origin)
void install_branch_config(int flag, const char *local, const char *origin, const char *remote) void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
{ {
const char *shortname = remote + 11;
int remote_is_branch = !prefixcmp(remote, "refs/heads/");
struct strbuf key = STRBUF_INIT; struct strbuf key = STRBUF_INIT;
int rebasing = should_setup_rebase(origin); int rebasing = should_setup_rebase(origin);
if (remote_is_branch
&& !strcmp(local, shortname)
&& !origin) {
warning("Not setting branch %s as its own upstream.",
local);
return;
}
strbuf_addf(&key, "branch.%s.remote", local); strbuf_addf(&key, "branch.%s.remote", local);
git_config_set(key.buf, origin ? origin : "."); git_config_set(key.buf, origin ? origin : ".");
@ -71,8 +81,8 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
strbuf_addstr(&key, origin ? "remote" : "local"); strbuf_addstr(&key, origin ? "remote" : "local");
/* Are we tracking a proper "branch"? */ /* Are we tracking a proper "branch"? */
if (!prefixcmp(remote, "refs/heads/")) { if (remote_is_branch) {
strbuf_addf(&key, " branch %s", remote + 11); strbuf_addf(&key, " branch %s", shortname);
if (origin) if (origin)
strbuf_addf(&key, " from %s", origin); strbuf_addf(&key, " from %s", origin);
} }