Skip to content

Commit 07c01b9

Browse files
bmwillgitster
authored andcommitted
ls-files: pass through safe options for --recurse-submodules
Pass through some known-safe options when recursing into submodules. (--cached, -v, -t, -z, --debug, --eol) Signed-off-by: Brandon Williams <bmwill@google.com> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent e77aa33 commit 07c01b9

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

builtin/ls-files.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static int line_terminator = '\n';
3030
static int debug_mode;
3131
static int show_eol;
3232
static int recurse_submodules;
33+
static struct argv_array submodules_options = ARGV_ARRAY_INIT;
3334

3435
static const char *prefix;
3536
static const char *super_prefix;
@@ -168,6 +169,25 @@ static void show_killed_files(struct dir_struct *dir)
168169
}
169170
}
170171

172+
/*
173+
* Compile an argv_array with all of the options supported by --recurse_submodules
174+
*/
175+
static void compile_submodule_options(const struct dir_struct *dir, int show_tag)
176+
{
177+
if (line_terminator == '\0')
178+
argv_array_push(&submodules_options, "-z");
179+
if (show_tag)
180+
argv_array_push(&submodules_options, "-t");
181+
if (show_valid_bit)
182+
argv_array_push(&submodules_options, "-v");
183+
if (show_cached)
184+
argv_array_push(&submodules_options, "--cached");
185+
if (show_eol)
186+
argv_array_push(&submodules_options, "--eol");
187+
if (debug_mode)
188+
argv_array_push(&submodules_options, "--debug");
189+
}
190+
171191
/**
172192
* Recursively call ls-files on a submodule
173193
*/
@@ -182,6 +202,9 @@ static void show_gitlink(const struct cache_entry *ce)
182202
argv_array_push(&cp.args, "ls-files");
183203
argv_array_push(&cp.args, "--recurse-submodules");
184204

205+
/* add supported options */
206+
argv_array_pushv(&cp.args, submodules_options.argv);
207+
185208
cp.git_cmd = 1;
186209
cp.dir = ce->name;
187210
status = run_command(&cp);
@@ -567,11 +590,12 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
567590
if (require_work_tree && !is_inside_work_tree())
568591
setup_work_tree();
569592

593+
if (recurse_submodules)
594+
compile_submodule_options(&dir, show_tag);
595+
570596
if (recurse_submodules &&
571597
(show_stage || show_deleted || show_others || show_unmerged ||
572-
show_killed || show_modified || show_resolve_undo ||
573-
show_valid_bit || show_tag || show_eol || with_tree ||
574-
(line_terminator == '\0')))
598+
show_killed || show_modified || show_resolve_undo || with_tree))
575599
die("ls-files --recurse-submodules unsupported mode");
576600

577601
if (recurse_submodules && error_unmatch)

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ test_expect_success 'ls-files correctly outputs files in submodule' '
3434
test_cmp expect actual
3535
'
3636

37+
test_expect_success 'ls-files correctly outputs files in submodule with -z' '
38+
lf_to_nul >expect <<-\EOF &&
39+
.gitmodules
40+
a
41+
b/b
42+
submodule/c
43+
EOF
44+
45+
git ls-files --recurse-submodules -z >actual &&
46+
test_cmp expect actual
47+
'
48+
3749
test_expect_success 'ls-files does not output files not added to a repo' '
3850
cat >expect <<-\EOF &&
3951
.gitmodules
@@ -86,15 +98,11 @@ test_incompatible_with_recurse_submodules () {
8698
"
8799
}
88100

89-
test_incompatible_with_recurse_submodules -z
90-
test_incompatible_with_recurse_submodules -v
91-
test_incompatible_with_recurse_submodules -t
92101
test_incompatible_with_recurse_submodules --deleted
93102
test_incompatible_with_recurse_submodules --modified
94103
test_incompatible_with_recurse_submodules --others
95104
test_incompatible_with_recurse_submodules --stage
96105
test_incompatible_with_recurse_submodules --killed
97106
test_incompatible_with_recurse_submodules --unmerged
98-
test_incompatible_with_recurse_submodules --eol
99107

100108
test_done

0 commit comments

Comments
 (0)