ls-tree: detect and error on --name-only --name-status
The --name-only and --name-status options are synonyms, but let's detect and error if both are provided. In addition let's add explicit --format tests for the combination of these various options. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Teng Long <dyroneteng@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Mar 23, 2022 at 17:13 UTC
0f8878359207191195867ebd499abba3710f9f4b
2 files changed
+19
-7
builtin/ls-tree.c
+10
-1
@@ -41,6 +41,7 @@ static enum ls_tree_cmdmode {
41
MODE_DEFAULT = 0,
42
MODE_LONG,
43
MODE_NAME_ONLY,
44
+ MODE_NAME_STATUS,
45
MODE_OBJECT_ONLY,
46
} cmdmode;
47
@@ -296,7 +297,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
297
OPT_CMDMODE(0, "name-only", &cmdmode, N_("list only filenames"),
298
MODE_NAME_ONLY),
299
OPT_CMDMODE(0, "name-status", &cmdmode, N_("list only filenames"),
299
- MODE_NAME_ONLY),
300
+ MODE_NAME_STATUS),
301
OPT_CMDMODE(0, "object-only", &cmdmode, N_("list only objects"),
302
MODE_OBJECT_ONLY),
303
OPT_SET_INT(0, "full-name", &chomp_prefix,
@@ -322,6 +323,14 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
323
ls_tree_prefix = prefix = NULL;
324
chomp_prefix = 0;
325
}
326
+ /*
327
+ * We wanted to detect conflicts between --name-only and
328
+ * --name-status, but once we're done with that subsequent
329
+ * code should only need to check the primary name.
330
+ */
331
+ if (cmdmode == MODE_NAME_STATUS)
332
+ cmdmode = MODE_NAME_ONLY;
333
+
334
/* -d -r should imply -t, but -d by itself should not have to. */
335
if ( (LS_TREE_ONLY|LS_RECURSIVE) ==
336
((LS_TREE_ONLY|LS_RECURSIVE) & ls_options))
t/t3103-ls-tree-misc.sh
+9
-6
@@ -24,15 +24,18 @@ test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
24
'
25
26
for opts in \
27
- "--name-only --long" \
28
- "--name-status --long" \
29
- "--name-only --object-only" \
27
+ "--long --name-only" \
28
+ "--name-only --name-status" \
29
"--name-status --object-only" \
31
- "--object-only --long" \
32
- "--object-only --format"
30
+ "--object-only --long"
31
do
32
test_expect_success "usage: incompatible options: $opts" '
33
test_expect_code 129 git ls-tree $opts $tree
36
- '
34
+ '
35
+
36
+ one_opt=$(echo "$opts" | cut -d' ' -f1)
37
+ test_expect_success "usage: incompatible options: $one_opt and --format" '
38
+ test_expect_code 129 git ls-tree $one_opt --format=fmt $tree
39
+ '
40
done
41
test_done