From: Michael J Gruber <git@drmicha.warpmail.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Randall S. Becker" <rsbecker@nexbridge.com>,
mdconf@seznam.cz, git@vger.kernel.org
Subject: Re: Git Feature Request - show current branch
Date: Fri, 20 Feb 2015 11:16:39 +0100 [thread overview]
Message-ID: <54E70987.4060904@drmicha.warpmail.net> (raw)
In-Reply-To: <xmqqr3tlzsao.fsf@gitster.dls.corp.google.com>
Junio C Hamano venit, vidit, dixit 19.02.2015 19:10:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
>
>> Randall S. Becker venit, vidit, dixit 19.02.2015 14:32:
>>> git symbolic-ref --short HEAD
>>
>> That errors out when HEAD is detached.
>
> Isn't that what you would want to happen anyway?
>
> if current=$(that command)
> then
> you know $current is checked out
> else
> you know HEAD is detached
> fi
>
> If you used another command that gives either the name of the
> current branch or 4-letter H-E-A-D without any other indication, you
> cannot tell if you checked out the "HEAD" branch aka refs/heads/HEAD
> or you are not on any branch. The former would happen after doing
> this:
>
> $ git update-ref refs/heads/HEAD HEAD
> $ git checkout HEAD
>
> Of course, this is not a recommended practice, and "git branch"
> these days refuses to create refs/heads/HEAD to discourage you from
> doing so by mistake, but there is no guarantee that the repository
> whatever script you are writing to work in was created and used by
> sane people ;-) so you would want to be defensive, no?
>
If you want to be defenive, don't use --abbrev-ref, just git rev-parse
--symbolic-full-name HEAD
The original request was for a one-liner, I think.
Michael
prev parent reply other threads:[~2015-02-20 10:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-19 13:14 Git Feature Request - show current branch mdconf
2015-02-19 13:32 ` Randall S. Becker
2015-02-19 16:21 ` Michael J Gruber
2015-02-19 18:10 ` Junio C Hamano
2015-02-20 10:16 ` Michael J Gruber [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54E70987.4060904@drmicha.warpmail.net \
--to=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mdconf@seznam.cz \
--cc=rsbecker@nexbridge.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.
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 NNTP newsgroup(s).