diff: make sure work tree side is shown as 0{40} when different
Ping Yin noticed that "git diff-index --raw" shows 0{40} when work tree has submodule difference, but "git diff --raw" didn't correctly do so. There was a mistake in the diffcore_skip_stat_unmatch() that was meant to clean up the stat-only difference for running diff between the index and work tree and diff between the tree and the work tree, to cause it re-read from the submodule repository HEAD. When ce_stat_match() says work tree is different, we should always say 0{40} on the work tree side. This patch fixes the issue, and adds tests. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Mar 2, 2008 at 00:07 UTC
2b459b483cb264d3e9a39cd7857da2ccab08179f
2 files changed
+55
-5
diff.c
+2
-5
@@ -3187,11 +3187,8 @@ static void diffcore_apply_filter(const char *filter)
3187
static int diff_filespec_is_identical(struct diff_filespec *one,
3188
struct diff_filespec *two)
3189
{
3190
- if (S_ISGITLINK(one->mode)) {
3191
- diff_fill_sha1_info(one);
3192
- diff_fill_sha1_info(two);
3193
- return !hashcmp(one->sha1, two->sha1);
3194
- }
3190
+ if (S_ISGITLINK(one->mode))
3191
+ return 0;
3192
if (diff_populate_filespec(one, 0))
3193
return 0;
3194
if (diff_populate_filespec(two, 0))
t/t4027-diff-submodule.sh
new
+53
@@ -0,0 +1,53 @@
1
+#!/bin/sh
2
+
3
+test_description='difference in submodules'
4
+
5
+. ./test-lib.sh
6
+. ../diff-lib.sh
7
+
8
+_z40=0000000000000000000000000000000000000000
9
+test_expect_success setup '
10
+ test_tick &&
11
+ test_create_repo sub &&
12
+ (
13
+ cd sub &&
14
+ echo hello >world &&
15
+ git add world &&
16
+ git commit -m submodule
17
+ ) &&
18
+
19
+ test_tick &&
20
+ echo frotz >nitfol &&
21
+ git add nitfol sub &&
22
+ git commit -m superproject &&
23
+
24
+ (
25
+ cd sub &&
26
+ echo goodbye >world &&
27
+ git add world &&
28
+ git commit -m "submodule #2"
29
+ ) &&
30
+
31
+ set x $(
32
+ cd sub &&
33
+ git rev-list HEAD
34
+ ) &&
35
+ echo ":160000 160000 $3 $_z40 M sub" >expect
36
+'
37
+
38
+test_expect_success 'git diff --raw HEAD' '
39
+ git diff --raw --abbrev=40 HEAD >actual &&
40
+ diff -u expect actual
41
+'
42
+
43
+test_expect_success 'git diff-index --raw HEAD' '
44
+ git diff-index --raw HEAD >actual.index &&
45
+ diff -u expect actual.index
46
+'
47
+
48
+test_expect_success 'git diff-files --raw' '
49
+ git diff-files --raw >actual.files &&
50
+ diff -u expect actual.files
51
+'
52
+
53
+test_done