git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Kaartic Sivaraam <kaarticsivaraam91196@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Ambiguity warning printed twice ?
Date: Thu, 22 Jun 2017 10:23:48 -0400	[thread overview]
Message-ID: <20170622142348.hwlrajujgrxo6nwf@sigill.intra.peff.net> (raw)
In-Reply-To: <1498135581.2089.1.camel@gmail.com>

On Thu, Jun 22, 2017 at 06:16:21PM +0530, Kaartic Sivaraam wrote:

> I accidentally noticed a weird behaviour of 'git status'. In a
> repository I created a branch with the name 'HEAD' by chance. When I
> run 'git status' in the repository it prints a warning about an
> ambiguous reference about 'HEAD' which is expected but it prints it
> twice which seems suspicious.
> 
>     $ git branch
>       HEAD
>       master
>     * test
> 
>     $ git status
>     warning: refname 'HEAD' is ambiguous.
>     warning: refname 'HEAD' is ambiguous.
>     On branch test
>     ....
> 
> Any reasons behind this behaviour or is this a bug?

It's not unreasonable for a complex command like git-status to need to
resolve HEAD multiple times. You can see how we get to each case by
running:

  gdb /path/to/git-status

and then doing:

  break warning
  run

Each time it breaks, you can run "bt" to get a backtrace, and then "c"
to continue".

It looks like the first one is when cmd_status() resolves the HEAD to
see if we are on an unborn branch, and the second is done by wt_status
to diff the index against HEAD. It would probably be possible to feed
the results of the first resolution to wt-status. But that would just
help this case, and I wouldn't be surprised if there are other commands
that do multiple resolutions (or even scripts which call multiple
commands).

Since warning should be rare, we could keep track of which names we've
warned about and suppress multiple warnings. That would help
single-process cases like this, but scripts which call multiple Git
commands would still show multiple warnings. I don't know if that's
worth doing or not.

-Peff

  reply	other threads:[~2017-06-22 14:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-22 12:46 Ambiguity warning printed twice ? Kaartic Sivaraam
2017-06-22 14:23 ` Jeff King [this message]
2017-06-23  2:11   ` Kaartic Sivaraam

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=20170622142348.hwlrajujgrxo6nwf@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=kaarticsivaraam91196@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).