Skip to content

Commit 079f298

Browse files
committed
Merge branch 'jl/submodule-summary-diff-files'
* jl/submodule-summary-diff-files: Documentaqtion/git-submodule.txt: Typofix git submodule summary: add --files option
2 parents d6d994d + ef92e1a commit 079f298

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

Documentation/git-submodule.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SYNOPSIS
1515
'git submodule' [--quiet] init [--] [<path>...]
1616
'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]
1717
[--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>...]
1919
'git submodule' [--quiet] foreach <command>
2020
'git submodule' [--quiet] sync [--] [<path>...]
2121

@@ -127,7 +127,11 @@ summary::
127127
Show commit summary between the given commit (defaults to HEAD) and
128128
working tree/index. For a submodule in question, a series of commits
129129
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 the super project 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).
131135

132136
foreach::
133137
Evaluates an arbitrary shell command in each checked out submodule.
@@ -169,6 +173,11 @@ OPTIONS
169173
commands typically use the commit found in the submodule HEAD, but
170174
with this option, the commit stored in the index is used instead.
171175

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+
172181
-n::
173182
--summary-limit::
174183
This option is only valid for the summary command.

git-submodule.sh

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 2007 Lars Hjemli
66

7-
USAGE="[--quiet] [--cached] \
7+
USAGE="[--quiet] [--cached|--files] \
88
[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch] [--rebase|--merge]|summary [-n|--summary-limit <n>] [<commit>]] \
99
[--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
1010
OPTIONS_SPEC=
@@ -16,6 +16,7 @@ command=
1616
branch=
1717
reference=
1818
cached=
19+
files=
1920
nofetch=
2021
update=
2122

@@ -460,6 +461,7 @@ set_name_rev () {
460461
cmd_summary() {
461462
summary_limit=-1
462463
for_status=
464+
diff_cmd=diff-index
463465

464466
# parse $args after "submodule ... summary".
465467
while test $# -ne 0
@@ -468,6 +470,9 @@ cmd_summary() {
468470
--cached)
469471
cached="$1"
470472
;;
473+
--files)
474+
files="$1"
475+
;;
471476
--for-status)
472477
for_status="$1"
473478
;;
@@ -504,9 +509,17 @@ cmd_summary() {
504509
head=HEAD
505510
fi
506511

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+
507520
cd_to_toplevel
508521
# Get modified modules cared by user
509-
modules=$(git diff-index $cached --raw $head -- "$@" |
522+
modules=$(git $diff_cmd $cached --raw $head -- "$@" |
510523
egrep '^:([0-7]* )?160000' |
511524
while read mod_src mod_dst sha1_src sha1_dst status name
512525
do
@@ -520,7 +533,7 @@ cmd_summary() {
520533

521534
test -z "$modules" && return
522535

523-
git diff-index $cached --raw $head -- $modules |
536+
git $diff_cmd $cached --raw $head -- $modules |
524537
egrep '^:([0-7]* )?160000' |
525538
cut -c2- |
526539
while read mod_src mod_dst sha1_src sha1_dst status name

t/t7401-submodule-summary.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ test_expect_success 'modified submodule(forward)' "
5656
EOF
5757
"
5858

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+
5968
commit_file sm1 &&
6069
cd sm1 &&
6170
git reset --hard HEAD~2 >/dev/null &&
@@ -114,6 +123,15 @@ test_expect_success 'typechanged submodule(submodule->blob), --cached' "
114123
EOF
115124
"
116125

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+
117135
rm -rf sm1 &&
118136
git checkout-index sm1
119137
test_expect_success 'typechanged submodule(submodule->blob)' "
@@ -205,4 +223,8 @@ test_expect_success '--for-status' "
205223
EOF
206224
"
207225

226+
test_expect_success 'fail when using --files together with --cached' "
227+
test_must_fail git submodule summary --files --cached
228+
"
229+
208230
test_done

0 commit comments

Comments
 (0)