summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-07-26 14:13:15 -0700
committerJunio C Hamano <gitster@pobox.com>2023-07-26 14:13:15 -0700
commit8ae477e2b4a50cb64864e2e0b6d16de35d7bc5cf (patch)
tree12ef943a6340c30983e642a20f8bf0da095999fd
parent89672f14d52ebe5001ccf0bd44a11355817cc262 (diff)
parent991c552916d3c8fa464acfca135b4235e11792bf (diff)
downloadgit-8ae477e2b4a50cb64864e2e0b6d16de35d7bc5cf.tar.xz
Merge branch 'rs/ls-tree-no-full-name-fix'
Command line parser fix. * rs/ls-tree-no-full-name-fix: ls-tree: fix --no-full-name
-rw-r--r--builtin/ls-tree.c7
-rwxr-xr-xt/t3101-ls-tree-dirname.sh8
2 files changed, 11 insertions, 4 deletions
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 53073d64cb..f558db5f3b 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -343,7 +343,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
struct object_id oid;
struct tree *tree;
int i, full_tree = 0;
- int chomp_prefix = prefix && *prefix;
+ int full_name = !prefix || !*prefix;
read_tree_fn_t fn = NULL;
enum ls_tree_cmdmode cmdmode = MODE_DEFAULT;
int null_termination = 0;
@@ -365,8 +365,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
MODE_NAME_STATUS),
OPT_CMDMODE(0, "object-only", &cmdmode, N_("list only objects"),
MODE_OBJECT_ONLY),
- OPT_SET_INT(0, "full-name", &chomp_prefix,
- N_("use full path names"), 0),
+ OPT_BOOL(0, "full-name", &full_name, N_("use full path names")),
OPT_BOOL(0, "full-tree", &full_tree,
N_("list entire tree; not just current directory "
"(implies --full-name)")),
@@ -387,7 +386,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
if (full_tree)
prefix = NULL;
- options.prefix = chomp_prefix ? prefix : NULL;
+ options.prefix = full_name ? NULL : prefix;
/*
* We wanted to detect conflicts between --name-only and
diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh
index 217006d1bf..5af2dac0e4 100755
--- a/t/t3101-ls-tree-dirname.sh
+++ b/t/t3101-ls-tree-dirname.sh
@@ -154,6 +154,14 @@ EOF
test_output
'
+test_expect_success 'ls-tree --no-full-name' '
+ git -C path0 ls-tree --no-full-name $tree a >current &&
+ cat >expected <<-EOF &&
+ 040000 tree X a
+ EOF
+ test_output
+'
+
test_expect_success 'ls-tree --full-tree' '
(
cd path1/b/c &&