Skip to content

Commit 1071dea

Browse files
committed
Merge branch 'aj/ls-files-format-fix'
Fix for a "ls-files --format="%(path)" that produced nonsense output, which was a bug in 2.38. * aj/ls-files-format-fix: ls-files: fix "--format" output of relative paths
2 parents 15108de + cfb62dd commit 1071dea

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

builtin/ls-files.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,15 @@ static void write_name(const char *name)
8989

9090
static void write_name_to_buf(struct strbuf *sb, const char *name)
9191
{
92-
const char *rel = relative_path(name, prefix_len ? prefix : NULL, sb);
92+
struct strbuf buf = STRBUF_INIT;
93+
const char *rel = relative_path(name, prefix_len ? prefix : NULL, &buf);
9394

9495
if (line_terminator)
9596
quote_c_style(rel, sb, NULL, 0);
9697
else
9798
strbuf_addstr(sb, rel);
99+
100+
strbuf_release(&buf);
98101
}
99102

100103
static const char *get_tag(const struct cache_entry *ce, const char *tag)

t/t3013-ls-files-format.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ test_expect_success 'git ls-files --format path v.s. -s' '
5454
test_cmp expect actual
5555
'
5656

57+
test_expect_success 'git ls-files --format with relative path' '
58+
cat >expect <<-\EOF &&
59+
../o1.txt
60+
../o2.txt
61+
../o3.txt
62+
../o4.txt
63+
../o5.txt
64+
../o6.txt
65+
EOF
66+
mkdir sub &&
67+
cd sub &&
68+
git ls-files --format="%(path)" ":/" >../actual &&
69+
cd .. &&
70+
test_cmp expect actual
71+
'
72+
5773
test_expect_success 'git ls-files --format with -m' '
5874
echo change >o1.txt &&
5975
cat >expect <<-\EOF &&

0 commit comments

Comments
 (0)