{"thread":{"id":"2852","subject":"[PATCH] We do not like \"HEAD\" as a new branch name","startedAt":"2005-12-15T11:46:54Z","lastAt":"2005-12-16T11:32:26Z","messageCount":10,"participants":["Johannes Schindelin","H. Peter Anvin","Alex Riesen","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"13682","messageId":"Pine.LNX.4.63.0512151244230.22400@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2852","inReplyTo":null,"subject":"[PATCH] We do not like \"HEAD\" as a new branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-15T11:46:54Z","receivedAt":"2005-12-15T11:46:54Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nThis makes git-check-ref-format fail for \"HEAD\". Since the check is only\nexecuted when creating refs, the existing symbolic ref is safe.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tThis patch was triggered by Alex' mail. Even if it should be a \n\trare case, it could catch some bad errors: Just try to run\n\n\t\tgit checkout -b HEAD\n\n\tand imagine what a regular git user makes of the error \n\tmessage...\n\n refs.c                 |    5 +++++\n t/t3300-funny-names.sh |    2 ++\n 2 files changed, 7 insertions(+), 0 deletions(-)\n\n04d60f0bf743f91d03e03acebf123db527cb7507\ndiff --git a/refs.c b/refs.c\nindex bda45f7..293bfe7 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -332,6 +332,11 @@ int check_ref_format(const char *ref)\n \t\tif (ch == '.' || bad_ref_char(ch))\n \t\t\treturn -1;\n \n+\t\t/* do not allow \"HEAD\" as ref name */\n+\t\tif (ch == 'H' && (!strcmp(cp, \"EAD\") ||\n+\t\t\t\t\t!strncmp(cp, \"EAD/\", 4)))\n+\t\t\treturn -1;\n+\n \t\t/* scan the rest of the path component */\n \t\twhile ((ch = *cp++) != 0) {\n \t\t\tif (bad_ref_char(ch))\ndiff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh\nindex 897c378..8ebd896 100755\n--- a/t/t3300-funny-names.sh\n+++ b/t/t3300-funny-names.sh\n@@ -139,4 +139,6 @@ test_expect_success 'git-apply non-git d\n \t git-apply --stat | sed -e \"s/|.*//\" -e \"s/ *\\$//\" >current &&\n \t diff -u expected current'\n \n+test_expect_failure 'HEAD is special' 'git checkout -b HEAD'\n+\n test_done\n-- \n0.99.9.GIT\n"},{"id":"13692","messageId":"43A19962.2000202@zytor.com","threadId":"2852","inReplyTo":"Pine.LNX.4.63.0512151244230.22400@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] We do not like \"HEAD\" as a new branch name","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2005-12-15T16:27:14Z","receivedAt":"2005-12-15T16:27:14Z","isPatch":true,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"Johannes Schindelin wrote:\n> This makes git-check-ref-format fail for \"HEAD\". Since the check is only\n> executed when creating refs, the existing symbolic ref is safe.\n\n> diff --git a/refs.c b/refs.c\n> index bda45f7..293bfe7 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -332,6 +332,11 @@ int check_ref_format(const char *ref)\n>  \t\tif (ch == '.' || bad_ref_char(ch))\n>  \t\t\treturn -1;\n>  \n> +\t\t/* do not allow \"HEAD\" as ref name */\n> +\t\tif (ch == 'H' && (!strcmp(cp, \"EAD\") ||\n> +\t\t\t\t\t!strncmp(cp, \"EAD/\", 4)))\n> +\t\t\treturn -1;\n> +\n>  \t\t/* scan the rest of the path component */\n>  \t\twhile ((ch = *cp++) != 0) {\n\nIf you're have to open-code it, you might want to just do it all the way:\n\nif (ch == 'H' && cp[0] == 'E' && cp[1] == 'A' && cp[2] == 'D' &&\n     (cp[3] == '\\0' || cp[3] == '/'))\n\n\t-hpa\n"},{"id":"13693","messageId":"Pine.LNX.4.63.0512151737240.3542@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2852","inReplyTo":"43A19962.2000202@zytor.com","subject":"Re: [PATCH] We do not like \"HEAD\" as a new branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-15T16:40:05Z","receivedAt":"2005-12-15T16:40:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 15 Dec 2005, H. Peter Anvin wrote:\n\n> Johannes Schindelin wrote:\n> > This makes git-check-ref-format fail for \"HEAD\". Since the check is only\n> > executed when creating refs, the existing symbolic ref is safe.\n> \n> > diff --git a/refs.c b/refs.c\n> > index bda45f7..293bfe7 100644\n> > --- a/refs.c\n> > +++ b/refs.c\n> > @@ -332,6 +332,11 @@ int check_ref_format(const char *ref)\n> >  \t\tif (ch == '.' || bad_ref_char(ch))\n> >  \t\t\treturn -1;\n> >  +\t\t/* do not allow \"HEAD\" as ref name */\n> > +\t\tif (ch == 'H' && (!strcmp(cp, \"EAD\") ||\n> > +\t\t\t\t\t!strncmp(cp, \"EAD/\", 4)))\n> > +\t\t\treturn -1;\n> > +\n> >  \t\t/* scan the rest of the path component */\n> >  \t\twhile ((ch = *cp++) != 0) {\n> \n> If you're have to open-code it, you might want to just do it all the way:\n> \n> if (ch == 'H' && cp[0] == 'E' && cp[1] == 'A' && cp[2] == 'D' &&\n>     (cp[3] == '\\0' || cp[3] == '/'))\n\n;-)\n\nI don't really care. I could have used !strcmp(cp - 1, \"HEAD\"), just as \nwell...\n\nCiao,\nDscho\n"},{"id":"13695","messageId":"81b0412b0512150900j5b328e2fu72ffd8820e5140b7@mail.gmail.com","threadId":"2852","inReplyTo":"Pine.LNX.4.63.0512151737240.3542@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] We do not like \"HEAD\" as a new branch name","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2005-12-15T17:00:42Z","receivedAt":"2005-12-15T17:00:42Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"On 12/15/05, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> >\n> > If you're have to open-code it, you might want to just do it all the way:\n> >\n> I don't really care. I could have used !strcmp(cp - 1, \"HEAD\"), just as\n> well...\n>\n\n...which would be more readable and greppable.\n"},{"id":"13697","messageId":"7vacf2p320.fsf@assigned-by-dhcp.cox.net","threadId":"2852","inReplyTo":"Pine.LNX.4.63.0512151244230.22400@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] We do not like \"HEAD\" as a new branch name","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-15T19:34:31Z","receivedAt":"2005-12-15T19:34:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> +\t\t/* do not allow \"HEAD\" as ref name */\n> +\t\tif (ch == 'H' && (!strcmp(cp, \"EAD\") ||\n> +\t\t\t\t\t!strncmp(cp, \"EAD/\", 4)))\n\nWhy forbid HEAD in the middle, like \"refs/heads/HEAD/frotz\"?\nConfusion avoidance?\n\nWe might want to forbid anything that matches /^.*_?HEAD$/ to catch\nORIG_HEAD for example, though.\n"},{"id":"13702","messageId":"Pine.LNX.4.63.0512152339530.4962@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2852","inReplyTo":"7vacf2p320.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] We do not like \"HEAD\" as a new branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-15T22:41:26Z","receivedAt":"2005-12-15T22:41:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 15 Dec 2005, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > +\t\t/* do not allow \"HEAD\" as ref name */\n> > +\t\tif (ch == 'H' && (!strcmp(cp, \"EAD\") ||\n> > +\t\t\t\t\t!strncmp(cp, \"EAD/\", 4)))\n> \n> Why forbid HEAD in the middle, like \"refs/heads/HEAD/frotz\"?\n> Confusion avoidance?\n\nExactly.\n\n> We might want to forbid anything that matches /^.*_?HEAD$/ to catch\n> ORIG_HEAD for example, though.\n\nOkay, I think this is what *I* would want to be illegal:\n\nHEAD,\nORIG_HEAD,\nFETCH_HEAD\nMERGE_HEAD\n\nOthers? Or should I really test for just *anything* ending in _HEAD \nbesides HEAD itself?\n\nCiao,\nDscho\n"},{"id":"13707","messageId":"7v4q5alyms.fsf@assigned-by-dhcp.cox.net","threadId":"2852","inReplyTo":"Pine.LNX.4.63.0512152339530.4962@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] We do not like \"HEAD\" as a new branch name","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-15T23:38:19Z","receivedAt":"2005-12-15T23:38:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Okay, I think this is what *I* would want to be illegal:\n>\n> HEAD,\n> ORIG_HEAD,\n> FETCH_HEAD\n> MERGE_HEAD\n>\n> Others? Or should I really test for just *anything* ending in _HEAD \n> besides HEAD itself?\n\nJust to futureproof ourselves, how about this?\n\n\t/^(?:.*/)?(?:[A-Z0-9]+_)?HEAD$/\n\nThe last path component being \"HEAD\" or capital-or-digit\nfollowed by underscore followed by \"HEAD\".\n"},{"id":"13715","messageId":"Pine.LNX.4.63.0512160238300.6530@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2852","inReplyTo":"7v4q5alyms.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] We do not like \"HEAD\" as a new branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-16T01:40:25Z","receivedAt":"2005-12-16T01:40:25Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 15 Dec 2005, Junio C Hamano wrote:\n\n> Just to futureproof ourselves, how about this?\n> \n> \t/^(?:.*/)?(?:[A-Z0-9]+_)?HEAD$/\n> \n> The last path component being \"HEAD\" or capital-or-digit\n> followed by underscore followed by \"HEAD\".\n\nOkay. Why not go the full nine yards, and not be difficult about it:\n\ndiff --git a/refs.c b/refs.c\n--- a/refs.c\n+++ b/refs.c\n@@ -345,6 +345,11 @@ int check_ref_format(const char *ref)\n \t\tif (!ch) {\n \t\t\tif (level < 2)\n \t\t\t\treturn -1; /* at least of form \"heads/blah\" */\n+\n+\t\t\t/* do not allow ref name to end in \"HEAD\" */\n+\t\t\tif (cp - ref > 4 && !strcmp(cp - 4, \"HEAD\"))\n+\t\t\t\treturn -1;\n+\n \t\t\treturn 0;\n \t\t}\n \t}\n\nCiao,\nDscho\n"},{"id":"13720","messageId":"7v8xullfct.fsf@assigned-by-dhcp.cox.net","threadId":"2852","inReplyTo":"Pine.LNX.4.63.0512160238300.6530@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] We do not like \"HEAD\" as a new branch name","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-16T06:34:42Z","receivedAt":"2005-12-16T06:34:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Okay. Why not go the full nine yards, and not be difficult about it:\n\nThat's fine.  There is an off-by-one in your code, though.\nI've committed it with a tweak.\n"},{"id":"13723","messageId":"Pine.LNX.4.63.0512161231100.28757@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2852","inReplyTo":"7v8xullfct.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] We do not like \"HEAD\" as a new branch name","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-16T11:32:26Z","receivedAt":"2005-12-16T11:32:26Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 15 Dec 2005, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > Okay. Why not go the full nine yards, and not be difficult about it:\n> \n> That's fine.  There is an off-by-one in your code, though.\n> I've committed it with a tweak.\n\nThanks. I did test it (quickly), and t3300 said it was fine. Strange.\n\nCiao,\nDscho\n"}]}