Skip to content

Commit 0f88783

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Teng Long <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cab851c commit 0f88783

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

builtin/ls-tree.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static enum ls_tree_cmdmode {
4141
MODE_DEFAULT = 0,
4242
MODE_LONG,
4343
MODE_NAME_ONLY,
44+
MODE_NAME_STATUS,
4445
MODE_OBJECT_ONLY,
4546
} cmdmode;
4647

@@ -296,7 +297,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
296297
OPT_CMDMODE(0, "name-only", &cmdmode, N_("list only filenames"),
297298
MODE_NAME_ONLY),
298299
OPT_CMDMODE(0, "name-status", &cmdmode, N_("list only filenames"),
299-
MODE_NAME_ONLY),
300+
MODE_NAME_STATUS),
300301
OPT_CMDMODE(0, "object-only", &cmdmode, N_("list only objects"),
301302
MODE_OBJECT_ONLY),
302303
OPT_SET_INT(0, "full-name", &chomp_prefix,
@@ -322,6 +323,14 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
322323
ls_tree_prefix = prefix = NULL;
323324
chomp_prefix = 0;
324325
}
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+
325334
/* -d -r should imply -t, but -d by itself should not have to. */
326335
if ( (LS_TREE_ONLY|LS_RECURSIVE) ==
327336
((LS_TREE_ONLY|LS_RECURSIVE) & ls_options))

t/t3103-ls-tree-misc.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@ test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
2424
'
2525

2626
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" \
3029
"--name-status --object-only" \
31-
"--object-only --long" \
32-
"--object-only --format"
30+
"--object-only --long"
3331
do
3432
test_expect_success "usage: incompatible options: $opts" '
3533
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+
'
3740
done
3841
test_done

0 commit comments

Comments
 (0)