Skip to content

Commit 8ae477e

Browse files
committed
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
2 parents 89672f1 + 991c552 commit 8ae477e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

builtin/ls-tree.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
343343
struct object_id oid;
344344
struct tree *tree;
345345
int i, full_tree = 0;
346-
int chomp_prefix = prefix && *prefix;
346+
int full_name = !prefix || !*prefix;
347347
read_tree_fn_t fn = NULL;
348348
enum ls_tree_cmdmode cmdmode = MODE_DEFAULT;
349349
int null_termination = 0;
@@ -365,8 +365,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
365365
MODE_NAME_STATUS),
366366
OPT_CMDMODE(0, "object-only", &cmdmode, N_("list only objects"),
367367
MODE_OBJECT_ONLY),
368-
OPT_SET_INT(0, "full-name", &chomp_prefix,
369-
N_("use full path names"), 0),
368+
OPT_BOOL(0, "full-name", &full_name, N_("use full path names")),
370369
OPT_BOOL(0, "full-tree", &full_tree,
371370
N_("list entire tree; not just current directory "
372371
"(implies --full-name)")),
@@ -387,7 +386,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix)
387386

388387
if (full_tree)
389388
prefix = NULL;
390-
options.prefix = chomp_prefix ? prefix : NULL;
389+
options.prefix = full_name ? NULL : prefix;
391390

392391
/*
393392
* We wanted to detect conflicts between --name-only and

t/t3101-ls-tree-dirname.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ EOF
154154
test_output
155155
'
156156

157+
test_expect_success 'ls-tree --no-full-name' '
158+
git -C path0 ls-tree --no-full-name $tree a >current &&
159+
cat >expected <<-EOF &&
160+
040000 tree X a
161+
EOF
162+
test_output
163+
'
164+
157165
test_expect_success 'ls-tree --full-tree' '
158166
(
159167
cd path1/b/c &&

0 commit comments

Comments
 (0)