Skip to content

Commit 290eada

Browse files
jonathantanmygitster
authored andcommitted
ls-files: support --recurse-submodules --stage
e77aa33 ("ls-files: optionally recurse into submodules", 2016-10-10) taught ls-files the --recurse-submodules argument, but only in a limited set of circumstances. In particular, --stage was unsupported, perhaps because there was no repo_find_unique_abbrev(), which was only introduced in 8bb9557 ("sha1-name.c: add repo_find_unique_abbrev_r()", 2019-04-16). This function is needed for using --recurse-submodules with --stage. Now that we have repo_find_unique_abbrev(), teach support for this combination of arguments. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6ebfd0 commit 290eada

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Documentation/git-ls-files.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ a space) at the start of each line:
156156

157157
--recurse-submodules::
158158
Recursively calls ls-files on each active submodule in the repository.
159-
Currently there is only support for the --cached mode.
159+
Currently there is only support for the --cached and --stage modes.
160160

161161
--abbrev[=<n>]::
162162
Instead of showing the full 40-byte hexadecimal object

builtin/ls-files.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
244244
printf("%s%06o %s %d\t",
245245
tag,
246246
ce->ce_mode,
247-
find_unique_abbrev(&ce->oid, abbrev),
247+
repo_find_unique_abbrev(repo, &ce->oid, abbrev),
248248
ce_stage(ce));
249249
}
250250
write_eolinfo(repo->index, ce, fullname);
@@ -726,7 +726,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
726726
setup_work_tree();
727727

728728
if (recurse_submodules &&
729-
(show_stage || show_deleted || show_others || show_unmerged ||
729+
(show_deleted || show_others || show_unmerged ||
730730
show_killed || show_modified || show_resolve_undo || with_tree))
731731
die("ls-files --recurse-submodules unsupported mode");
732732

t/t3007-ls-files-recurse-submodules.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ test_expect_success 'ls-files correctly outputs files in submodule' '
3434
test_cmp expect actual
3535
'
3636

37+
test_expect_success '--stage' '
38+
GITMODULES_HASH=$(git rev-parse HEAD:.gitmodules) &&
39+
A_HASH=$(git rev-parse HEAD:a) &&
40+
B_HASH=$(git rev-parse HEAD:b/b) &&
41+
C_HASH=$(git -C submodule rev-parse HEAD:c) &&
42+
43+
cat >expect <<-EOF &&
44+
100644 $GITMODULES_HASH 0 .gitmodules
45+
100644 $A_HASH 0 a
46+
100644 $B_HASH 0 b/b
47+
100644 $C_HASH 0 submodule/c
48+
EOF
49+
50+
git ls-files --stage --recurse-submodules >actual &&
51+
test_cmp expect actual
52+
'
53+
3754
test_expect_success 'ls-files correctly outputs files in submodule with -z' '
3855
lf_to_nul >expect <<-\EOF &&
3956
.gitmodules
@@ -292,7 +309,6 @@ test_incompatible_with_recurse_submodules () {
292309
test_incompatible_with_recurse_submodules --deleted
293310
test_incompatible_with_recurse_submodules --modified
294311
test_incompatible_with_recurse_submodules --others
295-
test_incompatible_with_recurse_submodules --stage
296312
test_incompatible_with_recurse_submodules --killed
297313
test_incompatible_with_recurse_submodules --unmerged
298314

0 commit comments

Comments
 (0)