git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Johan Herland <johan@herland.net>
Cc: git@vger.kernel.org, Jacob Helwig <jacob.helwig@gmail.com>,
	Ping Yin <pkufranky@gmail.com>
Subject: Re: [PATCH] submodule summary: Don't barf when invoked in an empty repo
Date: Wed, 17 Feb 2010 01:10:05 -0500	[thread overview]
Message-ID: <20100217061005.GA520@coredump.intra.peff.net> (raw)
In-Reply-To: <201002161121.14613.johan@herland.net>

On Tue, Feb 16, 2010 at 11:21:14AM +0100, Johan Herland wrote:

> I'm working from the simple test case in the below patch, I get the
> following output with your proposed fix:
> 
>   [...]
>   trace: built-in: git 'rev-parse' '-q' '--verify' '^0'
>   [...]
>   trace: built-in: git 'diff-index' '--raw' 'HEAD' '--'
>   fatal: bad revision 'HEAD'
>   [...]
> 
> I.e. your fix doesn't work because $1 is empty (not "HEAD") at this point.

Ah, right. I was testing "git status" which calls "git submodule summary
HEAD", but your test uses the assumed HEAD. And both need fixing.

> My alternative patch (below) does pass my test case (and all the other
> tests as well)
> 
> I'd still like an ACK from the original author (Ping Yin) as well, as I'm
> not sure if I overlooked something by removing the "$1^0".

Your patch looks correct to me. I don't really see how dropping the "^0"
will have any effect. rev-parse --verify already prefers revisions to
files, and diff-index should peel if needed.

Which, btw, seems like a mini-bug here. The point of this code is to say
"if we have an argument, is it a revision? If so, shift it off.
Otherwise, put it (and any other arguments) after the -- as a file
limiter".

Usually if I have a branch "master" and a file "master", git will
complain about the ambiguity unless I use an explicit "--" separator.
But here it always takes it as a revision, no questions asked. Or if I
am in "--files" mode, that argument is simply removed and ignored (see
just below where we unset $head).

Probably it should be re-ordered as

  if test -n "$files"; then
     ...
  else
     if rev=$(git rev-parse -q --verify --default HEAD "$1")
       ...
  fi

It just doesn't come up much because usually having branch names and
filenames the same is sufficiently annoying that nobody does it.

-Peff

      reply	other threads:[~2010-02-17  6:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-16  4:19 Fatal error running status in new repo Jacob Helwig
2010-02-16  6:05 ` Jeff King
2010-02-16  6:24   ` Jacob Helwig
2010-02-16  6:47     ` Jeff King
2010-02-16  7:03       ` [PATCH] dwim_ref: fix dangling symref warning Jeff King
2010-02-16  7:21     ` Fatal error running status in new repo Jeff King
2010-02-16 10:21       ` [PATCH] submodule summary: Don't barf when invoked in an empty repo Johan Herland
2010-02-17  6:10         ` Jeff King [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=20100217061005.GA520@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=jacob.helwig@gmail.com \
    --cc=johan@herland.net \
    --cc=pkufranky@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.
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).