git submodule summary: add --files option
git submodule summary is providing similar functionality for submodules as git diff-index does for a git project (including the meaning of --cached). But the analogon to git diff-files is missing, so add a --files option to summarize the differences between the index of the super project and the last commit checked out in the working tree of the submodule. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jens Lehmann committed
Aug 13, 2009 at 21:32 UTC
1c244f6ee5775b227177a66cdcf49a410d9d6871
3 files changed
+49
-5
Documentation/git-submodule.txt
+11
-2
@@ -15,7 +15,7 @@ SYNOPSIS
15
'git submodule' [--quiet] init [--] [<path>...]
16
'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]
17
[--reference <repository>] [--merge] [--] [<path>...]
18
-'git submodule' [--quiet] summary [--cached] [--summary-limit <n>] [commit] [--] [<path>...]
18
+'git submodule' [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
19
'git submodule' [--quiet] foreach <command>
20
'git submodule' [--quiet] sync [--] [<path>...]
21
@@ -127,7 +127,11 @@ summary::
127
Show commit summary between the given commit (defaults to HEAD) and
128
working tree/index. For a submodule in question, a series of commits
129
in the submodule between the given super project commit and the
130
- index or working tree (switched by --cached) are shown.
130
+ index or working tree (switched by --cached) are shown. If the option
131
+ --files is given, show the series of commits in the submodule between
132
+ the index of super project the and the working tree of the submodule
133
+ (this option doesn't allow to use the --cached option or to provide an
134
+ explicit commit).
135
136
foreach::
137
Evaluates an arbitrary shell command in each checked out submodule.
@@ -169,6 +173,11 @@ OPTIONS
173
commands typically use the commit found in the submodule HEAD, but
174
with this option, the commit stored in the index is used instead.
175
176
+--files::
177
+ This option is only valid for the summary command. This command
178
+ compares the commit in the index with that in the submodule HEAD
179
+ when this option is used.
180
+
181
-n::
182
--summary-limit::
183
This option is only valid for the summary command.
git-submodule.sh
+16
-3
@@ -4,7 +4,7 @@
4
#
5
# Copyright (c) 2007 Lars Hjemli
6
7
-USAGE="[--quiet] [--cached] \
7
+USAGE="[--quiet] [--cached|--files] \
8
[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch] [--rebase|--merge]|summary [-n|--summary-limit <n>] [<commit>]] \
9
[--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
10
OPTIONS_SPEC=
@@ -16,6 +16,7 @@ command=
16
branch=
17
reference=
18
cached=
19
+files=
20
nofetch=
21
update=
22
@@ -460,6 +461,7 @@ set_name_rev () {
461
cmd_summary() {
462
summary_limit=-1
463
for_status=
464
+ diff_cmd=diff-index
465
466
# parse $args after "submodule ... summary".
467
while test $# -ne 0
@@ -468,6 +470,9 @@ cmd_summary() {
470
--cached)
471
cached="$1"
472
;;
473
+ --files)
474
+ files="$1"
475
+ ;;
476
--for-status)
477
for_status="$1"
478
;;
@@ -504,9 +509,17 @@ cmd_summary() {
509
head=HEAD
510
fi
511
512
+ if [ -n "$files" ]
513
+ then
514
+ test -n "$cached" &&
515
+ die "--cached cannot be used with --files"
516
+ diff_cmd=diff-files
517
+ head=
518
+ fi
519
+
520
cd_to_toplevel
521
# Get modified modules cared by user
509
- modules=$(git diff-index $cached --raw $head -- "$@" |
522
+ modules=$(git $diff_cmd $cached --raw $head -- "$@" |
523
egrep '^:([0-7]* )?160000' |
524
while read mod_src mod_dst sha1_src sha1_dst status name
525
do
@@ -520,7 +533,7 @@ cmd_summary() {
533
534
test -z "$modules" && return
535
523
- git diff-index $cached --raw $head -- $modules |
536
+ git $diff_cmd $cached --raw $head -- $modules |
537
egrep '^:([0-7]* )?160000' |
538
cut -c2- |
539
while read mod_src mod_dst sha1_src sha1_dst status name
t/t7401-submodule-summary.sh
+22
@@ -56,6 +56,15 @@ test_expect_success 'modified submodule(forward)' "
56
EOF
57
"
58
59
+test_expect_success 'modified submodule(forward), --files' "
60
+ git submodule summary --files >actual &&
61
+ diff actual - <<-EOF
62
+* sm1 $head1...$head2 (1):
63
+ > Add foo3
64
+
65
+EOF
66
+"
67
+
68
commit_file sm1 &&
69
cd sm1 &&
70
git reset --hard HEAD~2 >/dev/null &&
@@ -114,6 +123,15 @@ test_expect_success 'typechanged submodule(submodule->blob), --cached' "
123
EOF
124
"
125
126
+test_expect_success 'typechanged submodule(submodule->blob), --files' "
127
+ git submodule summary --files >actual &&
128
+ diff actual - <<-EOF
129
+* sm1 $head5(blob)->$head4(submodule) (3):
130
+ > Add foo5
131
+
132
+EOF
133
+"
134
+
135
rm -rf sm1 &&
136
git checkout-index sm1
137
test_expect_success 'typechanged submodule(submodule->blob)' "
@@ -205,4 +223,8 @@ test_expect_success '--for-status' "
223
EOF
224
"
225
226
+test_expect_success 'fail when using --files together with --cached' "
227
+ test_must_fail git submodule summary --files --cached
228
+"
229
+
230
test_done