From: Johan Herland <johan@herland.net>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Jacob Helwig <jacob.helwig@gmail.com>,
Ping Yin <pkufranky@gmail.com>
Subject: [PATCH] submodule summary: Don't barf when invoked in an empty repo
Date: Tue, 16 Feb 2010 11:21:14 +0100 [thread overview]
Message-ID: <201002161121.14613.johan@herland.net> (raw)
In-Reply-To: <20100216072154.GF2169@coredump.intra.peff.net>
When invoking "git submodule summary" in an empty repo (which can be
indirectly done by setting status.submodulesummary = true), it currently
emits an error message (via "git diff-index") since HEAD points to an
unborn branch.
This patch adds handling of the HEAD-points-to-unborn-branch special case,
so that "git submodule summary" no longer emits this error message.
The patch also adds a test case that verifies the fix.
Suggested-by: Jeff King <peff@peff.net>
Signed-off-by: Johan Herland <johan@herland.net>
---
On Tuesday 16 February 2010, Jeff King wrote:
> It looks like this code (git-submodule.sh:556-562):
>
> if rev=$(git rev-parse -q --verify "$1^0")
> then
> head=$rev
> shift
> else
> head=HEAD
> fi
>
> is meant to guess whether the argument is a revision or a file limiter,
> and if the latter, assume HEAD was meant. Which obviously breaks down
> when the argument is HEAD and it is invalid. The patch below seems to
> fix it for me, but I have no idea if I am breaking something else.
>
> Can somebody more clueful about the submodule script take a look?
I don't know this code very well, but from looking at the commit introducing
this code (28f9af5: git-submodule summary: code framework), your analysis
makes sense. However, your fix doesn't work well for me.
> ---
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 664f217..4332992 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -555,10 +555,12 @@ cmd_summary() {
>
> if rev=$(git rev-parse -q --verify "$1^0")
> then
> head=$rev
> shift
> + elif test "$1" = "HEAD"; then
> + return
> else
> head=HEAD
> fi
>
> if [ -n "$files" ]
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.
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".
Have fun! :)
...Johan
git-submodule.sh | 7 +++++--
t/t7401-submodule-summary.sh | 7 +++++++
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 664f217..906b7b2 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -553,12 +553,15 @@ cmd_summary() {
test $summary_limit = 0 && return
- if rev=$(git rev-parse -q --verify "$1^0")
+ if rev=$(git rev-parse -q --verify --default HEAD $1)
then
head=$rev
shift
+ elif test -z "$1" -o "$1" = "HEAD"
+ then
+ return
else
- head=HEAD
+ head="HEAD"
fi
if [ -n "$files" ]
diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh
index d3c039f..cee319d 100755
--- a/t/t7401-submodule-summary.sh
+++ b/t/t7401-submodule-summary.sh
@@ -227,4 +227,11 @@ test_expect_success 'fail when using --files together with --cached' "
test_must_fail git submodule summary --files --cached
"
+test_expect_success 'should not fail in an empty repo' "
+ git init xyzzy &&
+ cd xyzzy &&
+ git submodule summary >output 2>&1 &&
+ test_cmp output /dev/null
+"
+
test_done
--
1.7.0.rc1.141.gd3fd
--
Johan Herland, <johan@herland.net>
www.herland.net
next prev parent reply other threads:[~2010-02-16 10:21 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 ` Johan Herland [this message]
2010-02-17 6:10 ` [PATCH] submodule summary: Don't barf when invoked in an empty repo Jeff King
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=201002161121.14613.johan@herland.net \
--to=johan@herland.net \
--cc=git@vger.kernel.org \
--cc=jacob.helwig@gmail.com \
--cc=peff@peff.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).