Skip to content

Commit d0f64dd

Browse files
pkufrankygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f43e2fd commit d0f64dd

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

git-submodule.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ set_name_rev () {
342342
#
343343
cmd_summary() {
344344
summary_limit=-1
345+
for_status=
345346

346347
# parse $args after "submodule ... summary".
347348
while test $# -ne 0
@@ -350,6 +351,9 @@ cmd_summary() {
350351
--cached)
351352
cached="$1"
352353
;;
354+
--for-status)
355+
for_status="$1"
356+
;;
353357
-n|--summary-limit)
354358
if summary_limit=$(($2 + 0)) 2>/dev/null && test "$summary_limit" = "$2"
355359
then
@@ -397,7 +401,8 @@ cmd_summary() {
397401
done
398402
)
399403

400-
test -n "$modules" &&
404+
test -z "$modules" && return
405+
401406
git diff-index $cached --raw $head -- $modules |
402407
grep -e '^:160000' -e '^:[0-7]* 160000' |
403408
cut -c2- |
@@ -499,7 +504,14 @@ cmd_summary() {
499504
echo
500505
fi
501506
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
503515
}
504516
#
505517
# List all submodules, prefixed with:

t/t7401-submodule-summary.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,17 @@ test_expect_success 'given commit' "
192192
EOF
193193
"
194194

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

0 commit comments

Comments
 (0)