@matheusbsbs / matheus-bagliano / commits / d0f64dd44d
Fork 0

git-submodule summary: --for-status option

The --for-status option is mainly used by builtin-status/commit. It adds 'Modified submodules:' line at top and '# ' prefix to all following lines. Signed-off-by: Ping Yin <pkufranky@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ping Yin committed Apr 12, 2008 at 23:05 UTC d0f64dd44d5f708f77380998b2c16bffe1e94050
2 files changed +27 -2
git-submodule.sh
+14 -2
@@ -342,6 +342,7 @@ set_name_rev () {
342 #
343 cmd_summary() {
344 summary_limit=-1
345 + for_status=
346
347 # parse $args after "submodule ... summary".
348 while test $# -ne 0
@@ -350,6 +351,9 @@ cmd_summary() {
351 --cached)
352 cached="$1"
353 ;;
354 + --for-status)
355 + for_status="$1"
356 + ;;
357 -n|--summary-limit)
358 if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
359 then
@@ -397,7 +401,8 @@ cmd_summary() {
401 done
402 )
403
400 - test -n "$modules" &&
404 + test -z "$modules" && return
405 +
406 git diff-index $cached --raw $head -- $modules |
407 grep -e '^:160000' -e '^:[0-7]* 160000' |
408 cut -c2- |
@@ -499,7 +504,14 @@ cmd_summary() {
504 echo
505 fi
506 echo
502 - done
507 + done |
508 + if test -n "$for_status"; then
509 + echo "# Modified submodules:"
510 + echo "#"
511 + sed -e 's|^|# |' -e 's|^# $|#|'
512 + else
513 + cat
514 + fi
515 }
516 #
517 # List all submodules, prefixed with:
t/t7401-submodule-summary.sh
+13
@@ -192,4 +192,17 @@ test_expect_success 'given commit' "
192 EOF
193 "
194
195 +test_expect_success '--for-status' "
196 + git submodule summary --for-status HEAD^ >actual &&
197 + test_cmp actual - <<EOF
198 +# Modified submodules:
199 +#
200 +# * sm1 $head6...0000000:
201 +#
202 +# * sm2 0000000...$head7 (2):
203 +# > Add foo9
204 +#
205 +EOF
206 +"
207 +
208 test_done