Merge branch 'jh/maint-submodule-status-in-void'
authorJunio C Hamano <gitster@pobox.com>
Tue, 2 Mar 2010 20:44:07 +0000 (12:44 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Mar 2010 20:44:07 +0000 (12:44 -0800)
* jh/maint-submodule-status-in-void:
submodule summary: Don't barf when invoked in an empty repo

git-submodule.sh
t/t7401-submodule-summary.sh
index 664f21721cb876eed7da167744066d834521c825..5869c00f2d5db4d8316002267a8605096357d5ed 100755 (executable)
@@ -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" ]
index d3c039f724c3a1247417b5fd29d6bd50a88f54be..cee319da0ae6ef9ec3b220adbb178e116713db2a 100755 (executable)
@@ -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