{"thread":{"id":"44120","subject":"v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name","startedAt":"2016-09-20T16:29:07Z","lastAt":"2016-09-21T17:54:40Z","messageCount":7,"participants":["Steffen Nurpmeso","Bryan Turner","Jakub Narębski","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"302223","messageId":"20160920162309.l0neYMQ3l%steffen@sdaoden.eu","threadId":"44120","inReplyTo":null,"subject":"v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name","fromName":"Steffen Nurpmeso","fromEmail":"steffen@sdaoden.eu","sentAt":"2016-09-20T16:23:09Z","receivedAt":"2016-09-20T16:29:07Z","isPatch":false,"sender":{"key":"steffen@sdaoden.eu","avatar":"https://gravatar.com/avatar/d49e696effa4b8f04abdee3c3567a1638260b8fa05df4f389a373db04fc8a1b3?d=mp&s=160"},"body":"Hello again,\n\nyah, sorry, i'm back again..\nI try to find a way to find the name of the current branch in an\nautomated way, because i need to ensure that a commit happens on\nit and no other branch.  Now the problem arises that the commit\nref at the time of that commit maybe shared in between several\ndifferent branches, but no more thereafter, of course:\n\n  ?0[steffen@wales ]$ git branch|grep '^*'\n  * stable/v14.9\n  ?0[steffen@wales ]$ git name-rev --name-only HEAD\n  stable/v14.8\n\nIs there another way except looking into .git/HEAD or using sed(1)\non the output of `branch' to find the right name?\nThank you.\nCiao!\n\n--steffen\n"},{"id":"302231","messageId":"CAGyf7-FR11Ludt3vNZX7Ek4n_JLSON5+Y9By83GvNgpg94TWcg@mail.gmail.com","threadId":"44120","inReplyTo":"20160920162309.l0neYMQ3l%steffen@sdaoden.eu","subject":"Re: v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name","fromName":"Bryan Turner","fromEmail":"bturner@atlassian.com","sentAt":"2016-09-20T18:54:37Z","receivedAt":"2016-09-20T18:54:44Z","isPatch":false,"sender":{"key":"bturner@atlassian.com","avatar":"https://gravatar.com/avatar/16bcf3167981c1ef7c804e502642366d888a35b0d0b0a4ca01fdc442aa1acb1e?d=mp&s=160"},"body":"On Tue, Sep 20, 2016 at 9:23 AM, Steffen Nurpmeso <steffen@sdaoden.eu> wrote:\n> Hello again,\n>\n> yah, sorry, i'm back again..\n> I try to find a way to find the name of the current branch in an\n> automated way, because i need to ensure that a commit happens on\n> it and no other branch.  Now the problem arises that the commit\n> ref at the time of that commit maybe shared in between several\n> different branches, but no more thereafter, of course:\n>\n>   ?0[steffen@wales ]$ git branch|grep '^*'\n>   * stable/v14.9\n>   ?0[steffen@wales ]$ git name-rev --name-only HEAD\n>   stable/v14.8\n>\n> Is there another way except looking into .git/HEAD or using sed(1)\n> on the output of `branch' to find the right name?\n\nHave you tried \"git symbolic-ref HEAD\"?\n\n$ git symbolic-ref HEAD\nrefs/heads/master\n\nIf you don't want the fully-qualified ref, you can add --short:\n\n$ git symbolic-ref --short HEAD\nmaster\n\n> Thank you.\n> Ciao!\n>\n> --steffen\n"},{"id":"302247","messageId":"20160920192944.hGZZKLLwD%steffen@sdaoden.eu","threadId":"44120","inReplyTo":"CAGyf7-FR11Ludt3vNZX7Ek4n_JLSON5+Y9By83GvNgpg94TWcg@mail.gmail.com","subject":"Re: v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name","fromName":"Steffen Nurpmeso","fromEmail":"steffen@sdaoden.eu","sentAt":"2016-09-20T19:29:44Z","receivedAt":"2016-09-20T19:28:57Z","isPatch":false,"sender":{"key":"steffen@sdaoden.eu","avatar":"https://gravatar.com/avatar/d49e696effa4b8f04abdee3c3567a1638260b8fa05df4f389a373db04fc8a1b3?d=mp&s=160"},"body":"Hey.\n\nBryan Turner <bturner@atlassian.com> wrote:\n |On Tue, Sep 20, 2016 at 9:23 AM, Steffen Nurpmeso <steffen@sdaoden.eu> \\\n |wrote:\n |> yah, sorry, i'm back again..\n |> I try to find a way to find the name of the current branch in an\n |> automated way, because i need to ensure that a commit happens on\n |> it and no other branch.  Now the problem arises that the commit\n |> ref at the time of that commit maybe shared in between several\n |> different branches, but no more thereafter, of course:\n |>\n |>   ?0[steffen@wales ]$ git branch|grep '^*'\n |>   * stable/v14.9\n |>   ?0[steffen@wales ]$ git name-rev --name-only HEAD\n |>   stable/v14.8\n |>\n |> Is there another way except looking into .git/HEAD or using sed(1)\n |> on the output of `branch' to find the right name?\n |\n |Have you tried \"git symbolic-ref HEAD\"?\n\nNot until now.\n\n |$ git symbolic-ref HEAD\n |refs/heads/master\n\nWorks.\n\n |If you don't want the fully-qualified ref, you can add --short:\n |\n |$ git symbolic-ref --short HEAD\n |master\n\nYep, works even better.  Fantastic.  Thank you.  And that command\nwas already existing when i have learned to use git(1), it is even\nin the progit-09.markdown as of 2011-09-22 that i have laying\naround.  Five years, and anything forgotten.  That is what you get\nfrom working with blinkers on.  Shame!\n\nThank you Bryan.\n\n--steffen\n"},{"id":"302271","messageId":"b1d35732-4b4c-e0c1-59da-44d3e3b28799@gmail.com","threadId":"44120","inReplyTo":"CAGyf7-FR11Ludt3vNZX7Ek4n_JLSON5+Y9By83GvNgpg94TWcg@mail.gmail.com","subject":"Re: v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2016-09-21T13:43:16Z","receivedAt":"2016-09-21T13:43:40Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"W dniu 20.09.2016 o 20:54, Bryan Turner pisze:\n> On Tue, Sep 20, 2016 at 9:23 AM, Steffen Nurpmeso <steffen@sdaoden.eu> wrote:\n>> Hello again,\n>>\n>> yah, sorry, i'm back again..\n>> I try to find a way to find the name of the current branch in an\n>> automated way, because i need to ensure that a commit happens on\n>> it and no other branch.  Now the problem arises that the commit\n>> ref at the time of that commit maybe shared in between several\n>> different branches, but no more thereafter, of course:\n>>\n>>   ?0[steffen@wales ]$ git branch|grep '^*'\n>>   * stable/v14.9\n\nNot good, 'git branch' is a porcelain (user facing) command, so it\noutput may change; e.g. '*' could be replaced with '•'. For example\noutput for detached HEAD had changed!\n\n>>   ?0[steffen@wales ]$ git name-rev --name-only HEAD\n>>   stable/v14.8\n>>\n>> Is there another way except looking into .git/HEAD or using sed(1)\n>> on the output of `branch' to find the right name?\n> \n> Have you tried \"git symbolic-ref HEAD\"?\n> \n> $ git symbolic-ref HEAD\n> refs/heads/master\n> \n> If you don't want the fully-qualified ref, you can add --short:\n> \n> $ git symbolic-ref --short HEAD\n> master\n\nThis does not work for detached HEAD, but perhaps you don't need\nto worry about this.\n\n  $ git rev-parse --symbolic-full-name HEAD\n  refs/heads/master\n\nBut\n\n  $ git checkout HEAD^0\n  Note: checking out 'HEAD^0'.\n\n  You are in 'detached HEAD' state. [...]\n \n  $ git rev-parse --symbolic-full-name HEAD\n  HEAD\n\n  $ git symbolic-ref HEAD\n  fatal: ref HEAD is not a symbolic ref\n\n  $ git branch\n  * (HEAD detached at 3e2ebf9)\n    master\n\n-- \nJakub Narębski\n\n"},{"id":"302273","messageId":"20160921142118.zintMuTEK%steffen@sdaoden.eu","threadId":"44120","inReplyTo":"b1d35732-4b4c-e0c1-59da-44d3e3b28799@gmail.com","subject":"Re: v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name","fromName":"Steffen Nurpmeso","fromEmail":"steffen@sdaoden.eu","sentAt":"2016-09-21T14:21:18Z","receivedAt":"2016-09-21T14:20:32Z","isPatch":false,"sender":{"key":"steffen@sdaoden.eu","avatar":"https://gravatar.com/avatar/d49e696effa4b8f04abdee3c3567a1638260b8fa05df4f389a373db04fc8a1b3?d=mp&s=160"},"body":"Hello.\n\nJakub Narębski <jnareb@gmail.com> wrote:\n |W dniu 20.09.2016 o 20:54, Bryan Turner pisze:\n |> On Tue, Sep 20, 2016 at 9:23 AM, Steffen Nurpmeso <steffen@sdaoden.eu> \\\n |> wrote:\n |>> Hello again,\n |>>\n |>> yah, sorry, i'm back again..\n |>> I try to find a way to find the name of the current branch in an\n |>> automated way, because i need to ensure that a commit happens on\n |>> it and no other branch.  Now the problem arises that the commit\n |>> ref at the time of that commit maybe shared in between several\n |>> different branches, but no more thereafter, of course:\n |>>\n |>>   ?0[steffen@wales ]$ git branch|grep '^*'\n |>>   * stable/v14.9\n |\n |Not good, 'git branch' is a porcelain (user facing) command, so it\n |output may change; e.g. '*' could be replaced with '•'. For example\n |output for detached HEAD had changed!\n\nOk.  I went the road Bryan suggested, i had only forgotten this.\nYes, it caused mysterious bugs once rev-parse reversed the output,\nbut i didn't understand the order at first, anyway.  With todays'\never-rotating distributions i don't even try to keep up; currently\nunthinkable to use the same release of an OS for five years, like\nFreeBSD 5.3.  Well.\n\n  ...\n |>> Is there another way except looking into .git/HEAD or using sed(1)\n |>> on the output of `branch' to find the right name?\n |> \n |> Have you tried \"git symbolic-ref HEAD\"?\n  ...\n |This does not work for detached HEAD, but perhaps you don't need\n |to worry about this.\n\nNo, not for me: it will only switch in between two different\nstable/ which exist.  But thanks, just give it to me!\n\n |  $ git rev-parse --symbolic-full-name HEAD\n |  refs/heads/master\n\nThis is a really good suggestion, which i will remember.  I didn't\nknow this at all yet:\n\n  $ git rev-parse --symbolic-full-name --abbrev-ref=strict HEAD\n\nSeems to do exactly what i want, non-fragile, then.\n\n ...\n |But\n ...\n |  You are in 'detached HEAD' state. [...]\n | \n |  $ git rev-parse --symbolic-full-name HEAD\n |  HEAD\n |\n |  $ git symbolic-ref HEAD\n |  fatal: ref HEAD is not a symbolic ref\n |\n |  $ git branch\n |  * (HEAD detached at 3e2ebf9)\n |    master\n\nAnd name-rev gives \"HEAD master~2\" in a test of mine, or only\n\"master~2\", or \"undefined\" if i use --tags, for completeness sake.\n\nThanks, Jakub.  I'm using the plumbing.\n\n--steffen\n"},{"id":"302288","messageId":"xmqq8tulb45n.fsf@gitster.mtv.corp.google.com","threadId":"44120","inReplyTo":"b1d35732-4b4c-e0c1-59da-44d3e3b28799@gmail.com","subject":"Re: v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-09-21T16:37:08Z","receivedAt":"2016-09-21T16:37:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakub Narębski <jnareb@gmail.com> writes:\n\n>> Have you tried \"git symbolic-ref HEAD\"?\n>> \n>> $ git symbolic-ref HEAD\n>> refs/heads/master\n>> \n>> If you don't want the fully-qualified ref, you can add --short:\n>> \n>> $ git symbolic-ref --short HEAD\n>> master\n>\n> This does not work for detached HEAD, but perhaps you don't need\n> to worry about this.\n\nI am not sure what you mean by \"does not work\".  Asking what ref\nHEAD points at to symbolic-ref will tell you it does not point at\nanything by exiting with non-zero status and that can be relied\nupon.\n\nAsking \"symbolic-ref HEAD\" has been the way how \"git branch\" and\nother commands find out what branch is currently checked out for\nalmost eternity (\"git symbolic-ref\" appeared in Git v0.99.8).\n\n"},{"id":"302304","messageId":"60391836-a1c3-bfbe-b2d0-476d8bc82044@gmail.com","threadId":"44120","inReplyTo":"xmqq8tulb45n.fsf@gitster.mtv.corp.google.com","subject":"Re: v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2016-09-21T17:54:17Z","receivedAt":"2016-09-21T17:54:40Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"W dniu 21.09.2016 o 18:37, Junio C Hamano pisze:\n> Jakub Narębski <jnareb@gmail.com> writes:\n>>> Have you tried \"git symbolic-ref HEAD\"?\n>>>\n>>> $ git symbolic-ref HEAD\n>>> refs/heads/master\n>>>\n>>> If you don't want the fully-qualified ref, you can add --short:\n>>>\n>>> $ git symbolic-ref --short HEAD\n>>> master\n>>\n>> This does not work for detached HEAD, but perhaps you don't need\n>> to worry about this.\n> \n> I am not sure what you mean by \"does not work\".  Asking what ref\n> HEAD points at to symbolic-ref will tell you it does not point at\n> anything by exiting with non-zero status and that can be relied\n> upon.\n> \n> Asking \"symbolic-ref HEAD\" has been the way how \"git branch\" and\n> other commands find out what branch is currently checked out for\n> almost eternity (\"git symbolic-ref\" appeared in Git v0.99.8).\n\nI'm sorry, I was wrong saying \"does not work\".  The problem is not\nthat it does not work, but that you need to take care of exit \ncondition to correctly support detached HEAD state, and not end\nwith empty name for a branch, for example...\n\nBut if handled correctly, git-symbolic-ref is as good as git-rev-parse\nas a plumbing to resolve current branch name.\n\nBest,\n-- \nJakub Narębski\n\n"}]}