@matheusbsbs / matheus-bagliano / commits / 85e2233f98
Fork 0

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>

Matthieu Moy committed Jan 18, 2010 at 22:44 UTC 85e2233f982f760d0e731b1258da2580834d8027
1 file changed +12 -2
branch.c
+12 -2
@@ -49,9 +49,19 @@ static int should_setup_rebase(const char *origin)
49
50 void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
51 {
52 + const char *shortname = remote + 11;
53 + int remote_is_branch = !prefixcmp(remote, "refs/heads/");
54 struct strbuf key = STRBUF_INIT;
55 int rebasing = should_setup_rebase(origin);
56
57 + if (remote_is_branch
58 + && !strcmp(local, shortname)
59 + && !origin) {
60 + warning("Not setting branch %s as its own upstream.",
61 + local);
62 + return;
63 + }
64 +
65 strbuf_addf(&key, "branch.%s.remote", local);
66 git_config_set(key.buf, origin ? origin : ".");
67
@@ -71,8 +81,8 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
81 strbuf_addstr(&key, origin ? "remote" : "local");
82
83 /* Are we tracking a proper "branch"? */
74 - if (!prefixcmp(remote, "refs/heads/")) {
75 - strbuf_addf(&key, " branch %s", remote + 11);
84 + if (remote_is_branch) {
85 + strbuf_addf(&key, " branch %s", shortname);
86 if (origin)
87 strbuf_addf(&key, " from %s", origin);
88 }