git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] submodule summary: Don't barf when invoked in an empty repo

From
Jeff King <peff@peff.net>
Date
Feb 17, 2010, 06:10 UTC
Message-ID
<20100217061005.GA520@coredump.intra.peff.net>
In-Reply-To
<201002161121.14613.johan@herland.net>
On Tue, Feb 16, 2010 at 11:21:14AM +0100, Johan Herland wrote:
Show 11 quoted lines
> 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.

Show 5 quoted lines
> 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
Previous: Johan Herland
Message 8 of 8 in “Fatal error running status in new repo”
  1. Jacob HelwigFeb 16, 2010
  2. Jeff KingFeb 16, 2010
  3. Jacob HelwigFeb 16, 2010
  4. Jeff KingFeb 16, 2010
  5. dwim_ref: fix dangling symref warningJeff King, Feb 16, 2010
  6. Jeff KingFeb 16, 2010
  7. submodule summary: Don't barf when invoked in an empty repoJohan Herland, Feb 16, 2010
  8. Jeff KingFeb 17, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.