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>
Brandon Williams committed
Oct 7, 2016 at 11:18 UTC
07c01b9fd927b35375bd3a7d4d9dbf7bb8509f09
2 files changed
+39
-7
builtin/ls-files.c
+27
-3
@@ -30,6 +30,7 @@ static int line_terminator = '\n';
30
static int debug_mode;
31
static int show_eol;
32
static int recurse_submodules;
33
+static struct argv_array submodules_options = ARGV_ARRAY_INIT;
34
35
static const char *prefix;
36
static const char *super_prefix;
@@ -168,6 +169,25 @@ static void show_killed_files(struct dir_struct *dir)
169
}
170
}
171
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
+
191
/**
192
* Recursively call ls-files on a submodule
193
*/
@@ -182,6 +202,9 @@ static void show_gitlink(const struct cache_entry *ce)
202
argv_array_push(&cp.args, "ls-files");
203
argv_array_push(&cp.args, "--recurse-submodules");
204
205
+ /* add supported options */
206
+ argv_array_pushv(&cp.args, submodules_options.argv);
207
+
208
cp.git_cmd = 1;
209
cp.dir = ce->name;
210
status = run_command(&cp);
@@ -567,11 +590,12 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
590
if (require_work_tree && !is_inside_work_tree())
591
setup_work_tree();
592
593
+ if (recurse_submodules)
594
+ compile_submodule_options(&dir, show_tag);
595
+
596
if (recurse_submodules &&
597
(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))
599
die("ls-files --recurse-submodules unsupported mode");
600
601
if (recurse_submodules && error_unmatch)
t/t3007-ls-files-recurse-submodules.sh
+12
-4
@@ -34,6 +34,18 @@ test_expect_success 'ls-files correctly outputs files in submodule' '
34
test_cmp expect actual
35
'
36
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
+
49
test_expect_success 'ls-files does not output files not added to a repo' '
50
cat >expect <<-\EOF &&
51
.gitmodules
@@ -86,15 +98,11 @@ test_incompatible_with_recurse_submodules () {
98
"
99
}
100
89
-test_incompatible_with_recurse_submodules -z
90
-test_incompatible_with_recurse_submodules -v
91
-test_incompatible_with_recurse_submodules -t
101
test_incompatible_with_recurse_submodules --deleted
102
test_incompatible_with_recurse_submodules --modified
103
test_incompatible_with_recurse_submodules --others
104
test_incompatible_with_recurse_submodules --stage
105
test_incompatible_with_recurse_submodules --killed
106
test_incompatible_with_recurse_submodules --unmerged
98
-test_incompatible_with_recurse_submodules --eol
107
108
test_done