From 3deea89c5feb0dfdfb99ea752f83497d97a3bdd5 Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Tue, 16 Feb 2010 11:21:14 +0100 Subject: 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 Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano diff --git a/git-submodule.sh b/git-submodule.sh index 664f217..5869c00 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+"$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 -- cgit v0.10.2-6-g49f6