Browse Source

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>
maint
Johan Herland 15 years ago committed by Junio C Hamano
parent
commit
3deea89c5f
  1. 7
      git-submodule.sh
  2. 7
      t/t7401-submodule-summary.sh

7
git-submodule.sh

@ -553,12 +553,15 @@ cmd_summary() {


test $summary_limit = 0 && return 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 then
head=$rev head=$rev
shift shift
elif test -z "$1" -o "$1" = "HEAD"
then
return
else else
head=HEAD head="HEAD"
fi fi


if [ -n "$files" ] if [ -n "$files" ]

7
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_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 test_done

Loading…
Cancel
Save