Skip to content

Commit 095ce95

Browse files
committed
diff-files: show unmerged entries correctly
Earlier, e9c8409 (diff-index --cached --raw: show tree entry on the LHS for unmerged entries., 2007-01-05) taught the command to show the object name and the mode from the entry coming from the tree side when comparing a tree with an unmerged index. This is a belated companion patch that teaches diff-files to show the mode from the entry coming from the working tree side, when comparing an unmerged index and the working tree. Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa7b290 commit 095ce95

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

diff-lib.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
111111

112112
if (ce_stage(ce)) {
113113
struct combine_diff_path *dpath;
114+
struct diff_filepair *pair;
115+
unsigned int wt_mode = 0;
114116
int num_compare_stages = 0;
115117
size_t path_len;
116118

@@ -129,15 +131,17 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
129131

130132
changed = check_removed(ce, &st);
131133
if (!changed)
132-
dpath->mode = ce_mode_from_stat(ce, st.st_mode);
134+
wt_mode = ce_mode_from_stat(ce, st.st_mode);
133135
else {
134136
if (changed < 0) {
135137
perror(ce->name);
136138
continue;
137139
}
138140
if (silent_on_removed)
139141
continue;
142+
wt_mode = 0;
140143
}
144+
dpath->mode = wt_mode;
141145

142146
while (i < entries) {
143147
struct cache_entry *nce = active_cache[i];
@@ -183,7 +187,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
183187
* Show the diff for the 'ce' if we found the one
184188
* from the desired stage.
185189
*/
186-
diff_unmerge(&revs->diffopt, ce->name);
190+
pair = diff_unmerge(&revs->diffopt, ce->name);
191+
if (wt_mode)
192+
pair->two->mode = wt_mode;
187193
if (ce_stage(ce) != diff_unmerged_stage)
188194
continue;
189195
}

t/t4046-diff-unmerged.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/sh
2+
3+
test_description='diff with unmerged index entries'
4+
. ./test-lib.sh
5+
6+
test_expect_success setup '
7+
for i in 0 1 2 3
8+
do
9+
blob=$(echo $i | git hash-object --stdin) &&
10+
eval "blob$i=$blob" &&
11+
eval "m$i=\"100644 \$blob$i $i\"" || break
12+
done &&
13+
paths= &&
14+
for b in o x
15+
do
16+
for o in o x
17+
do
18+
for t in o x
19+
do
20+
path="$b$o$t" &&
21+
case "$path" in ooo) continue ;; esac
22+
paths="$paths$path " &&
23+
p=" $path" &&
24+
case "$b" in x) echo "$m1$p" ;; esac &&
25+
case "$o" in x) echo "$m2$p" ;; esac &&
26+
case "$t" in x) echo "$m3$p" ;; esac ||
27+
break
28+
done || break
29+
done || break
30+
done >ls-files-s.expect &&
31+
git update-index --index-info <ls-files-s.expect &&
32+
git ls-files -s >ls-files-s.actual &&
33+
test_cmp ls-files-s.expect ls-files-s.actual
34+
'
35+
36+
test_expect_success 'diff-files -0' '
37+
for path in $paths
38+
do
39+
>"$path" &&
40+
echo ":000000 100644 $_z40 $_z40 U $path"
41+
done >diff-files-0.expect &&
42+
git diff-files -0 >diff-files-0.actual &&
43+
test_cmp diff-files-0.expect diff-files-0.actual
44+
'
45+
46+
test_expect_success 'diff-files -1' '
47+
for path in $paths
48+
do
49+
>"$path" &&
50+
echo ":000000 100644 $_z40 $_z40 U $path" &&
51+
case "$path" in
52+
x??) echo ":100644 100644 $blob1 $_z40 M $path"
53+
esac
54+
done >diff-files-1.expect &&
55+
git diff-files -1 >diff-files-1.actual &&
56+
test_cmp diff-files-1.expect diff-files-1.actual
57+
'
58+
59+
test_expect_success 'diff-files -2' '
60+
for path in $paths
61+
do
62+
>"$path" &&
63+
echo ":000000 100644 $_z40 $_z40 U $path" &&
64+
case "$path" in
65+
?x?) echo ":100644 100644 $blob2 $_z40 M $path"
66+
esac
67+
done >diff-files-2.expect &&
68+
git diff-files -2 >diff-files-2.actual &&
69+
test_cmp diff-files-2.expect diff-files-2.actual &&
70+
git diff-files >diff-files-default-2.actual &&
71+
test_cmp diff-files-2.expect diff-files-default-2.actual
72+
'
73+
74+
test_expect_success 'diff-files -3' '
75+
for path in $paths
76+
do
77+
>"$path" &&
78+
echo ":000000 100644 $_z40 $_z40 U $path" &&
79+
case "$path" in
80+
??x) echo ":100644 100644 $blob3 $_z40 M $path"
81+
esac
82+
done >diff-files-3.expect &&
83+
git diff-files -3 >diff-files-3.actual &&
84+
test_cmp diff-files-3.expect diff-files-3.actual
85+
'
86+
87+
test_done

0 commit comments

Comments
 (0)