Skip to content

Commit 3deea89

Browse files
jherlandgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johan Herland <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e923eae commit 3deea89

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

git-submodule.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,12 +553,15 @@ cmd_summary() {
553553

554554
test $summary_limit = 0 && return
555555

556-
if rev=$(git rev-parse -q --verify "$1^0")
556+
if rev=$(git rev-parse -q --verify --default HEAD ${1+"$1"})
557557
then
558558
head=$rev
559559
shift
560+
elif test -z "$1" -o "$1" = "HEAD"
561+
then
562+
return
560563
else
561-
head=HEAD
564+
head="HEAD"
562565
fi
563566

564567
if [ -n "$files" ]

t/t7401-submodule-summary.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,11 @@ test_expect_success 'fail when using --files together with --cached' "
227227
test_must_fail git submodule summary --files --cached
228228
"
229229

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+
230237
test_done

0 commit comments

Comments
 (0)