Skip to content

Commit 4197195

Browse files
committed
Merge branch 'ne/maint-1.6.0-diff-tree-t-r-show-directory'
* ne/maint-1.6.0-diff-tree-t-r-show-directory: diff-tree -r -t: include added/removed directories in the output
2 parents 3eb1e8e + df533f3 commit 4197195

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

t/t4037-diff-r-t-dirs.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/sh
2+
3+
test_description='diff -r -t shows directory additions and deletions'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success setup '
8+
mkdir dc dr dt &&
9+
>dc/1 &&
10+
>dr/2 &&
11+
>dt/3 &&
12+
>fc &&
13+
>fr &&
14+
>ft &&
15+
git add . &&
16+
test_tick &&
17+
git commit -m initial &&
18+
19+
rm -fr dt dr ft fr &&
20+
mkdir da ft &&
21+
for p in dc/1 da/4 dt ft/5 fc
22+
do
23+
echo hello >$p || exit
24+
done &&
25+
git add -u &&
26+
git add . &&
27+
test_tick &&
28+
git commit -m second
29+
'
30+
31+
cat >expect <<\EOF
32+
A da
33+
A da/4
34+
M dc
35+
M dc/1
36+
D dr
37+
D dr/2
38+
A dt
39+
D dt
40+
D dt/3
41+
M fc
42+
D fr
43+
D ft
44+
A ft
45+
A ft/5
46+
EOF
47+
48+
test_expect_success verify '
49+
git diff-tree -r -t --name-status HEAD^ HEAD >actual &&
50+
test_cmp expect actual
51+
'
52+
53+
test_done

tree-diff.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree
239239
if (!tree || type != OBJ_TREE)
240240
die("corrupt tree sha %s", sha1_to_hex(sha1));
241241

242+
if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE)) {
243+
newbase[baselen + pathlen] = 0;
244+
opt->add_remove(opt, *prefix, mode, sha1, newbase);
245+
newbase[baselen + pathlen] = '/';
246+
}
247+
242248
init_tree_desc(&inner, tree, size);
243249
show_tree(opt, prefix, &inner, newbase, baselen + 1 + pathlen);
244250

0 commit comments

Comments
 (0)