]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ls-tree: fix "--name-only" and "--long" combined use bug
authorTeng Long <dyroneteng@gmail.com>
Wed, 23 Mar 2022 09:13:08 +0000 (17:13 +0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 23 Mar 2022 18:38:39 +0000 (11:38 -0700)
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/YZK0MKCYAJmG+pSU@coredump.intra.peff.net/

Helped-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>
builtin/ls-tree.c
t/t3103-ls-tree-misc.sh

index d4be71bad24820cec75ca1decf763048f319b903..7be4c1322895d3b12498a2b2e1cd80614fb811b7 100644 (file)
@@ -123,12 +123,12 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
                        LS_SHOW_TREES),
                OPT_SET_INT('z', NULL, &line_termination,
                            N_("terminate entries with NUL byte"), 0),
-               OPT_BIT('l', "long", &ls_options, N_("include object size"),
-                       LS_SHOW_SIZE),
-               OPT_BIT(0, "name-only", &ls_options, N_("list only filenames"),
-                       LS_NAME_ONLY),
-               OPT_BIT(0, "name-status", &ls_options, N_("list only filenames"),
-                       LS_NAME_ONLY),
+               OPT_CMDMODE('l', "long", &ls_options, N_("include object size"),
+                           LS_SHOW_SIZE),
+               OPT_CMDMODE(0, "name-only", &ls_options, N_("list only filenames"),
+                           LS_NAME_ONLY),
+               OPT_CMDMODE(0, "name-status", &ls_options, N_("list only filenames"),
+                           LS_NAME_ONLY),
                OPT_SET_INT(0, "full-name", &chomp_prefix,
                            N_("use full path names"), 0),
                OPT_BOOL(0, "full-tree", &full_tree,
index d18ba1bd84bb473888c5e24191d79f9d0a792358..d9d7fa932f8be75870e0a1c634450b99af5a2135 100755 (executable)
@@ -23,4 +23,13 @@ test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
        test_must_fail git ls-tree -r HEAD
 '
 
+for opts in \
+       "--name-only --long" \
+       "--name-status --long"
+do
+       test_expect_success "usage: incompatible options: $opts" '
+               test_expect_code 129 git ls-tree $opts $tree
+    '
+done
+
 test_done