Skip to content

Commit f6b224d

Browse files
dyronegitster
authored andcommitted
ls-tree: fix "--name-only" and "--long" combined use bug
If we execute "git ls-tree" with combined "--name-only" and "--long" , only the pathname will be printed, the size is omitted (the original discoverer was Peff in [1]). This commit fix this issue by using `OPT_CMDMODE()` instead to make both of them mutually exclusive. [1] https://public-inbox.org/git/[email protected]/ Helped-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Teng Long <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87af0dd commit f6b224d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

builtin/ls-tree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
123123
LS_SHOW_TREES),
124124
OPT_SET_INT('z', NULL, &line_termination,
125125
N_("terminate entries with NUL byte"), 0),
126-
OPT_BIT('l', "long", &ls_options, N_("include object size"),
127-
LS_SHOW_SIZE),
128-
OPT_BIT(0, "name-only", &ls_options, N_("list only filenames"),
129-
LS_NAME_ONLY),
130-
OPT_BIT(0, "name-status", &ls_options, N_("list only filenames"),
131-
LS_NAME_ONLY),
126+
OPT_CMDMODE('l', "long", &ls_options, N_("include object size"),
127+
LS_SHOW_SIZE),
128+
OPT_CMDMODE(0, "name-only", &ls_options, N_("list only filenames"),
129+
LS_NAME_ONLY),
130+
OPT_CMDMODE(0, "name-status", &ls_options, N_("list only filenames"),
131+
LS_NAME_ONLY),
132132
OPT_SET_INT(0, "full-name", &chomp_prefix,
133133
N_("use full path names"), 0),
134134
OPT_BOOL(0, "full-tree", &full_tree,

t/t3103-ls-tree-misc.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
2323
test_must_fail git ls-tree -r HEAD
2424
'
2525

26+
for opts in \
27+
"--name-only --long" \
28+
"--name-status --long"
29+
do
30+
test_expect_success "usage: incompatible options: $opts" '
31+
test_expect_code 129 git ls-tree $opts $tree
32+
'
33+
done
34+
2635
test_done

0 commit comments

Comments
 (0)