submodule summary: Don't barf when invoked in an empty repo
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Feb 16, 2010 at 11:21 UTC
3deea89c5feb0dfdfb99ea752f83497d97a3bdd5
2 files changed
+12
-2
git-submodule.sh
+5
-2
@@ -553,12 +553,15 @@ cmd_summary() {
553
554
test $summary_limit = 0 && return
555
556
- if rev=$(git rev-parse -q --verify "$1^0")
556
+ if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
557
then
558
head=$rev
559
shift
560
+ elif test -z "$1" -o "$1" = "HEAD"
561
+ then
562
+ return
563
else
561
- head=HEAD
564
+ head="HEAD"
565
fi
566
567
if [ -n "$files" ]
t/t7401-submodule-summary.sh
+7
@@ -227,4 +227,11 @@ test_expect_success 'fail when using --files together with --cached' "
227
test_must_fail git submodule summary --files --cached
228
"
229
230
+test_expect_success 'should not fail in an empty repo' "
231
+ git init xyzzy &&
232
+ cd xyzzy &&
233
+ git submodule summary >output 2>&1 &&
234
+ test_cmp output /dev/null
235
+"
236
+
237
test_done