From: Thomas Rast Date: Tue, 14 Dec 2010 18:38:22 +0000 (+0100) Subject: branch: do not attempt to track HEAD implicitly X-Git-Tag: ko-pu~9^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=84c1a89588c598530c4b0d2297ddddea9ee68278;p=git.git branch: do not attempt to track HEAD implicitly With branch.autosetupmerge=always, 'HEAD' becomes a valid target for branch tracking. This is a bit silly, and in fact the code already guards against it when attempting it explicitly: $ git checkout HEAD^0 $ git branch -t foo fatal: Cannot setup tracking information; starting point is not a branch. Silently drop the HEAD candidate in the implicit (i.e. without -t flag) case, so that the branch starts out without an upstream. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- diff --git a/branch.c b/branch.c index 93dc866f8..19310e4e8 100644 --- a/branch.c +++ b/branch.c @@ -176,8 +176,12 @@ void create_branch(const char *head, break; case 1: /* Unique completion -- good, only if it is a real ref */ - if (explicit_tracking && !strcmp(real_ref, "HEAD")) - die("Cannot setup tracking information; starting point is not a branch."); + if (!strcmp(real_ref, "HEAD")) { + if (explicit_tracking) + die("Cannot setup tracking information; starting point is not a branch."); + else + real_ref = NULL; + } break; default: die("Ambiguous object name: '%s'.", start_name); diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index f54a53345..dce90de74 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -477,6 +477,15 @@ test_expect_success 'autosetuprebase always on an untracked remote branch' ' test "z$(git config branch.myr20.rebase)" = z ' +test_expect_success 'autosetuprebase always on detached HEAD' ' + git config branch.autosetupmerge always && + test_when_finished git checkout master && + git checkout HEAD^0 && + git branch my11 && + test -z "$(git config branch.my11.remote)" && + test -z "$(git config branch.my11.merge)" +' + test_expect_success 'detect misconfigured autosetuprebase (bad value)' ' git config branch.autosetuprebase garbage && test_must_fail git branch