{"thread":{"id":"26051","subject":"[PATCH] branch: do not attempt to track HEAD implicitly","startedAt":"2010-12-14T18:38:22Z","lastAt":"2010-12-17T05:55:27Z","messageCount":5,"participants":["Thomas Rast","Martin von Zweigbergk","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"158063","messageId":"6ee1f0174b757e25ab873d2d037545ac7db698ee.1292351886.git.trast@student.ethz.ch","threadId":"26051","inReplyTo":null,"subject":"[PATCH] branch: do not attempt to track HEAD implicitly","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-12-14T18:38:22Z","receivedAt":"2010-12-14T18:38:22Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"With branch.autosetupmerge=always, 'HEAD' becomes a valid target for\nbranch tracking.  This is a bit silly, and in fact the code already\nguards against it when attempting it explicitly:\n\n  $ git checkout HEAD^0\n  $ g branch -t foo\n  fatal: Cannot setup tracking information; starting point is not a branch.\n\nSilently drop the HEAD candidate in the implicit (i.e. without -t\nflag) case, so that the branch starts out without an upstream.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n branch.c          |    8 ++++++--\n t/t3200-branch.sh |    9 +++++++++\n 2 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex 93dc866..19310e4 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -176,8 +176,12 @@ void create_branch(const char *head,\n \t\tbreak;\n \tcase 1:\n \t\t/* Unique completion -- good, only if it is a real ref */\n-\t\tif (explicit_tracking && !strcmp(real_ref, \"HEAD\"))\n-\t\t\tdie(\"Cannot setup tracking information; starting point is not a branch.\");\n+\t\tif (!strcmp(real_ref, \"HEAD\")) {\n+\t\t\tif (explicit_tracking)\n+\t\t\t\tdie(\"Cannot setup tracking information; starting point is not a branch.\");\n+\t\t\telse\n+\t\t\t\treal_ref = NULL;\n+\t\t}\n \t\tbreak;\n \tdefault:\n \t\tdie(\"Ambiguous object name: '%s'.\", start_name);\ndiff --git a/t/t3200-branch.sh b/t/t3200-branch.sh\nindex f308235..0fa5c91 100755\n--- a/t/t3200-branch.sh\n+++ b/t/t3200-branch.sh\n@@ -488,6 +488,15 @@ test_expect_success 'autosetuprebase always on an untracked remote branch' '\n \ttest \"z$(git config branch.myr20.rebase)\" = z\n '\n \n+test_expect_success 'autosetuprebase always on detached HEAD' '\n+\tgit config branch.autosetupmerge always &&\n+\ttest_when_finished git checkout master &&\n+\tgit checkout HEAD^0 &&\n+\tgit branch my11 &&\n+\ttest -z \"$(git config branch.my11.remote)\" &&\n+\ttest -z \"$(git config branch.my11.merge)\"\n+'\n+\n test_expect_success 'detect misconfigured autosetuprebase (bad value)' '\n \tgit config branch.autosetuprebase garbage &&\n \ttest_must_fail git branch\n-- \n1.7.3.3.797.g7a32f\n"},{"id":"158129","messageId":"AANLkTi=PPx-pLEeR4gLw0KzV_=ZnuqqH_CGc6L7RzU7M@mail.gmail.com","threadId":"26051","inReplyTo":"6ee1f0174b757e25ab873d2d037545ac7db698ee.1292351886.git.trast@student.ethz.ch","subject":"Re: [PATCH] branch: do not attempt to track HEAD implicitly","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-12-15T00:50:44Z","receivedAt":"2010-12-15T00:50:44Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Tue, Dec 14, 2010 at 1:38 PM, Thomas Rast <trast@student.ethz.ch> wrote:\n> With branch.autosetupmerge=always, 'HEAD' becomes a valid target for\n> branch tracking.  This is a bit silly, and in fact the code already\n> guards against it when attempting it explicitly:\n>\n>  $ git checkout HEAD^0\n>  $ g branch -t foo\n\nmissing the \"it\" in \"git\"\n\n>  fatal: Cannot setup tracking information; starting point is not a branch.\n>\n> Silently drop the HEAD candidate in the implicit (i.e. without -t\n> flag) case, so that the branch starts out without an upstream.\n\nThanks. This has been on my todo list for a while.\n\nShould it only check for HEAD? How about ORIG_HEAD and FETCH_HEAD?\nSimply anything outside of refs/ maybe? Would that make sense?\n\n/Martin\n"},{"id":"158187","messageId":"201012151626.35366.trast@student.ethz.ch","threadId":"26051","inReplyTo":"AANLkTi=PPx-pLEeR4gLw0KzV_=ZnuqqH_CGc6L7RzU7M@mail.gmail.com","subject":"Re: [PATCH] branch: do not attempt to track HEAD implicitly","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2010-12-15T15:26:35Z","receivedAt":"2010-12-15T15:26:35Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Martin von Zweigbergk wrote:\n> On Tue, Dec 14, 2010 at 1:38 PM, Thomas Rast <trast@student.ethz.ch> wrote:\n> > Silently drop the HEAD candidate in the implicit (i.e. without -t\n> > flag) case, so that the branch starts out without an upstream.\n> \n> Thanks. This has been on my todo list for a while.\n> \n> Should it only check for HEAD? How about ORIG_HEAD and FETCH_HEAD?\n> Simply anything outside of refs/ maybe? Would that make sense?\n\nGood point.  It seems HEAD wins the dwim_ref() over the rest:\n\n$ g rev-parse HEAD ORIG_HEAD FETCH_HEAD\n79f9a226d33659f0e6a69429931d66b5f70c9708\n79f9a226d33659f0e6a69429931d66b5f70c9708\n79f9a226d33659f0e6a69429931d66b5f70c9708\n$ g branch test\n$ g config -l | grep branch.test.\n\nNot sure through which mechanism, however.\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"158200","messageId":"alpine.DEB.1.10.1012151909410.25560@debian","threadId":"26051","inReplyTo":"201012151626.35366.trast@student.ethz.ch","subject":"Re: [PATCH] branch: do not attempt to track HEAD implicitly","fromName":"Martin von Zweigbergk","fromEmail":"martin.von.zweigbergk@gmail.com","sentAt":"2010-12-15T18:30:04Z","receivedAt":"2010-12-15T18:30:04Z","isPatch":true,"sender":{"key":"martinvonz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/891642?v=4"},"body":"On Wed, 15 Dec 2010, Thomas Rast wrote:\n\n> Martin von Zweigbergk wrote:\n> > On Tue, Dec 14, 2010 at 1:38 PM, Thomas Rast <trast@student.ethz.ch> wrote:\n> > > Silently drop the HEAD candidate in the implicit (i.e. without -t\n> > > flag) case, so that the branch starts out without an upstream.\n> > \n> > Thanks. This has been on my todo list for a while.\n> > \n> > Should it only check for HEAD? How about ORIG_HEAD and FETCH_HEAD?\n> > Simply anything outside of refs/ maybe? Would that make sense?\n> \n> Good point.  It seems HEAD wins the dwim_ref() over the rest:\n> \n> $ g rev-parse HEAD ORIG_HEAD FETCH_HEAD\n> 79f9a226d33659f0e6a69429931d66b5f70c9708\n> 79f9a226d33659f0e6a69429931d66b5f70c9708\n> 79f9a226d33659f0e6a69429931d66b5f70c9708\n\nProbably a stupid question, but why are all three of them pointing to\nthe same commit? I guess that is what you want to show, but how did\nyou get there? If I run the same command (I assume your 'g' alias\nsimply calls git), I get three different commits (in general, of\ncourse).\n\n> $ g branch test\n> $ g config -l | grep branch.test.\n> \n> Not sure through which mechanism, however.\n\nThe scenario I meant is the following:\n\n$ git config branch.autosetupmerge always\n$ git branch test ORIG_HEAD\nBranch test set up to track local ref ORIG_HEAD.\n$ git config -l | grep branch.test\nbranch.test.remote=.\nbranch.test.merge=ORIG_HEAD\n\n\n/Martin\n"},{"id":"158266","messageId":"7vsjxxj640.fsf@alter.siamese.dyndns.org","threadId":"26051","inReplyTo":"201012151626.35366.trast@student.ethz.ch","subject":"Re: [PATCH] branch: do not attempt to track HEAD implicitly","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-12-17T05:55:27Z","receivedAt":"2010-12-17T05:55:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> writes:\n\n> Martin von Zweigbergk wrote:\n>> On Tue, Dec 14, 2010 at 1:38 PM, Thomas Rast <trast@student.ethz.ch> wrote:\n>> > Silently drop the HEAD candidate in the implicit (i.e. without -t\n>> > flag) case, so that the branch starts out without an upstream.\n>> \n>> Thanks. This has been on my todo list for a while.\n>> \n>> Should it only check for HEAD? How about ORIG_HEAD and FETCH_HEAD?\n>> Simply anything outside of refs/ maybe? Would that make sense?\n\nI was tempted to say \"limit to refs/heads/ and refs/remotes/\" but perhaps\npeople have custom namespaces defined in refs/ hierarchy and for some of\nthem the tracking may make sense.  How about ignoring the implicit track\nif the ref does not begin with refs/ to cover the obvious ones like HEAD,\nFETCH_HEAD, etc.?\n"}]}