From: Steffen Nurpmeso <steffen@sdaoden.eu>
To: "Jakub Narębski" <jnareb@gmail.com>
Cc: Bryan Turner <bturner@atlassian.com>, Git Users <git@vger.kernel.org>
Subject: Re: v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name
Date: Wed, 21 Sep 2016 16:21:18 +0200 [thread overview]
Message-ID: <20160921142118.zintMuTEK%steffen@sdaoden.eu> (raw)
In-Reply-To: <b1d35732-4b4c-e0c1-59da-44d3e3b28799@gmail.com>
Hello.
Jakub Narębski <jnareb@gmail.com> wrote:
|W dniu 20.09.2016 o 20:54, Bryan Turner pisze:
|> On Tue, Sep 20, 2016 at 9:23 AM, Steffen Nurpmeso <steffen@sdaoden.eu> \
|> wrote:
|>> Hello again,
|>>
|>> yah, sorry, i'm back again..
|>> I try to find a way to find the name of the current branch in an
|>> automated way, because i need to ensure that a commit happens on
|>> it and no other branch. Now the problem arises that the commit
|>> ref at the time of that commit maybe shared in between several
|>> different branches, but no more thereafter, of course:
|>>
|>> ?0[steffen@wales ]$ git branch|grep '^*'
|>> * stable/v14.9
|
|Not good, 'git branch' is a porcelain (user facing) command, so it
|output may change; e.g. '*' could be replaced with '•'. For example
|output for detached HEAD had changed!
Ok. I went the road Bryan suggested, i had only forgotten this.
Yes, it caused mysterious bugs once rev-parse reversed the output,
but i didn't understand the order at first, anyway. With todays'
ever-rotating distributions i don't even try to keep up; currently
unthinkable to use the same release of an OS for five years, like
FreeBSD 5.3. Well.
...
|>> Is there another way except looking into .git/HEAD or using sed(1)
|>> on the output of `branch' to find the right name?
|>
|> Have you tried "git symbolic-ref HEAD"?
...
|This does not work for detached HEAD, but perhaps you don't need
|to worry about this.
No, not for me: it will only switch in between two different
stable/ which exist. But thanks, just give it to me!
| $ git rev-parse --symbolic-full-name HEAD
| refs/heads/master
This is a really good suggestion, which i will remember. I didn't
know this at all yet:
$ git rev-parse --symbolic-full-name --abbrev-ref=strict HEAD
Seems to do exactly what i want, non-fragile, then.
...
|But
...
| You are in 'detached HEAD' state. [...]
|
| $ git rev-parse --symbolic-full-name HEAD
| HEAD
|
| $ git symbolic-ref HEAD
| fatal: ref HEAD is not a symbolic ref
|
| $ git branch
| * (HEAD detached at 3e2ebf9)
| master
And name-rev gives "HEAD master~2" in a test of mine, or only
"master~2", or "undefined" if i use --tags, for completeness sake.
Thanks, Jakub. I'm using the plumbing.
--steffen
next prev parent reply other threads:[~2016-09-21 14:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-20 16:23 v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name Steffen Nurpmeso
2016-09-20 18:54 ` Bryan Turner
2016-09-20 19:29 ` Steffen Nurpmeso
2016-09-21 13:43 ` Jakub Narębski
2016-09-21 14:21 ` Steffen Nurpmeso [this message]
2016-09-21 16:37 ` Junio C Hamano
2016-09-21 17:54 ` Jakub Narębski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160921142118.zintMuTEK%steffen@sdaoden.eu \
--to=steffen@sdaoden.eu \
--cc=bturner@atlassian.com \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).