Skip to content

Commit

Permalink
Merge branch 'jt/ls-files-stage-recurse'
Browse files Browse the repository at this point in the history
Many output modes of "ls-files" do not work with its
"--recurse-submodules" option, but the "-s" mode has been taught to
work with it.

* jt/ls-files-stage-recurse:
  ls-files: support --recurse-submodules --stage
  • Loading branch information
gitster committed Mar 7, 2022
2 parents 11da0a5 + 290eada commit 7a4e06c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Documentation/git-ls-files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ a space) at the start of each line:

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

--abbrev[=<n>]::
Instead of showing the full 40-byte hexadecimal object
Expand Down
4 changes: 2 additions & 2 deletions builtin/ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
printf("%s%06o %s %d\t",
tag,
ce->ce_mode,
find_unique_abbrev(&ce->oid, abbrev),
repo_find_unique_abbrev(repo, &ce->oid, abbrev),
ce_stage(ce));
}
write_eolinfo(repo->index, ce, fullname);
Expand Down Expand Up @@ -726,7 +726,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
setup_work_tree();

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

Expand Down
18 changes: 17 additions & 1 deletion t/t3007-ls-files-recurse-submodules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ test_expect_success 'ls-files correctly outputs files in submodule' '
test_cmp expect actual
'

test_expect_success '--stage' '
GITMODULES_HASH=$(git rev-parse HEAD:.gitmodules) &&
A_HASH=$(git rev-parse HEAD:a) &&
B_HASH=$(git rev-parse HEAD:b/b) &&
C_HASH=$(git -C submodule rev-parse HEAD:c) &&
cat >expect <<-EOF &&
100644 $GITMODULES_HASH 0 .gitmodules
100644 $A_HASH 0 a
100644 $B_HASH 0 b/b
100644 $C_HASH 0 submodule/c
EOF
git ls-files --stage --recurse-submodules >actual &&
test_cmp expect actual
'

test_expect_success 'ls-files correctly outputs files in submodule with -z' '
lf_to_nul >expect <<-\EOF &&
.gitmodules
Expand Down Expand Up @@ -292,7 +309,6 @@ test_incompatible_with_recurse_submodules () {
test_incompatible_with_recurse_submodules --deleted
test_incompatible_with_recurse_submodules --modified
test_incompatible_with_recurse_submodules --others
test_incompatible_with_recurse_submodules --stage
test_incompatible_with_recurse_submodules --killed
test_incompatible_with_recurse_submodules --unmerged

Expand Down

0 comments on commit 7a4e06c

Please sign in to comment.