@@ -27,29 +27,32 @@ Further, with -B and -M together, these should turn into two renames.
27
27
test_expect_success setup '
28
28
cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
29
29
cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
30
+ blob0_id=$(git hash-object file0) &&
31
+ blob1_id=$(git hash-object file1) &&
30
32
git update-index --add file0 file1 &&
31
33
git tag reference $(git write-tree)
32
34
'
33
35
34
36
test_expect_success ' change file1 with copy-edit of file0 and remove file0' '
35
37
sed -e "s/git/GIT/" file0 >file1 &&
38
+ blob2_id=$(git hash-object file1) &&
36
39
rm -f file0 &&
37
40
git update-index --remove file0 file1
38
41
'
39
42
40
43
test_expect_success ' run diff with -B (#1)' '
41
44
git diff-index -B --cached reference >current &&
42
- cat >expect <<-\ EOF &&
43
- :100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
44
- :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
45
+ cat >expect <<-EOF &&
46
+ :100644 000000 $blob0_id $ZERO_OID D file0
47
+ :100644 100644 $blob1_id $blob2_id M100 file1
45
48
EOF
46
49
compare_diff_raw expect current
47
50
'
48
51
49
52
test_expect_success ' run diff with -B and -M (#2)' '
50
53
git diff-index -B -M reference >current &&
51
- cat >expect <<-\ EOF &&
52
- :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec R100 file0 file1
54
+ cat >expect <<-EOF &&
55
+ :100644 100644 $blob0_id $blob2_id R100 file0 file1
53
56
EOF
54
57
compare_diff_raw expect current
55
58
'
@@ -66,33 +69,34 @@ test_expect_success 'swap file0 and file1' '
66
69
67
70
test_expect_success ' run diff with -B (#3)' '
68
71
git diff-index -B reference >current &&
69
- cat >expect <<-\ EOF &&
70
- :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100 file0
71
- :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
72
+ cat >expect <<-EOF &&
73
+ :100644 100644 $blob0_id $blob1_id M100 file0
74
+ :100644 100644 $blob1_id $blob0_id M100 file1
72
75
EOF
73
76
compare_diff_raw expect current
74
77
'
75
78
76
79
test_expect_success ' run diff with -B and -M (#4)' '
77
80
git diff-index -B -M reference >current &&
78
- cat >expect <<-\ EOF &&
79
- :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0
80
- :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 R100 file0 file1
81
+ cat >expect <<-EOF &&
82
+ :100644 100644 $blob1_id $blob1_id R100 file1 file0
83
+ :100644 100644 $blob0_id $blob0_id R100 file0 file1
81
84
EOF
82
85
compare_diff_raw expect current
83
86
'
84
87
85
88
test_expect_success ' make file0 into something completely different' '
86
89
rm -f file0 &&
87
90
test_ln_s_add frotz file0 &&
91
+ slink_id=$(printf frotz | git hash-object --stdin) &&
88
92
git update-index file1
89
93
'
90
94
91
95
test_expect_success ' run diff with -B (#5)' '
92
96
git diff-index -B reference >current &&
93
- cat >expect <<-\ EOF &&
94
- :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
95
- :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100 file1
97
+ cat >expect <<-EOF &&
98
+ :100644 120000 $blob0_id $slink_id T file0
99
+ :100644 100644 $blob1_id $blob0_id M100 file1
96
100
EOF
97
101
compare_diff_raw expect current
98
102
'
@@ -103,9 +107,9 @@ test_expect_success 'run diff with -B -M (#6)' '
103
107
# file0 changed from regular to symlink. file1 is the same as the preimage
104
108
# of file0. Because the change does not make file0 disappear, file1 is
105
109
# denoted as a copy of file0
106
- cat >expect <<-\ EOF &&
107
- :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
108
- :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 C file0 file1
110
+ cat >expect <<-EOF &&
111
+ :100644 120000 $blob0_id $slink_id T file0
112
+ :100644 100644 $blob0_id $blob0_id C file0 file1
109
113
EOF
110
114
compare_diff_raw expect current
111
115
'
@@ -115,9 +119,9 @@ test_expect_success 'run diff with -M (#7)' '
115
119
116
120
# This should not mistake file0 as the copy source of new file1
117
121
# due to type differences.
118
- cat >expect <<-\ EOF &&
119
- :100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T file0
120
- :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M file1
122
+ cat >expect <<-EOF &&
123
+ :100644 120000 $blob0_id $slink_id T file0
124
+ :100644 100644 $blob1_id $blob0_id M file1
121
125
EOF
122
126
compare_diff_raw expect current
123
127
'
@@ -128,25 +132,26 @@ test_expect_success 'file1 edited to look like file0 and file0 rename-edited to
128
132
git checkout-index -f -u -a &&
129
133
sed -e "s/git/GIT/" file0 >file1 &&
130
134
sed -e "s/git/GET/" file0 >file2 &&
135
+ blob3_id=$(git hash-object file2) &&
131
136
rm -f file0 &&
132
137
git update-index --add --remove file0 file1 file2
133
138
'
134
139
135
140
test_expect_success ' run diff with -B (#8)' '
136
141
git diff-index -B reference >current &&
137
- cat >expect <<-\ EOF &&
138
- :100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D file0
139
- :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100 file1
140
- :000000 100644 0000000000000000000000000000000000000000 69a939f651686f56322566e2fd76715947a24162 A file2
142
+ cat >expect <<-EOF &&
143
+ :100644 000000 $blob0_id $ZERO_OID D file0
144
+ :100644 100644 $blob1_id $blob2_id M100 file1
145
+ :000000 100644 $ZERO_OID $blob3_id A file2
141
146
EOF
142
147
compare_diff_raw expect current
143
148
'
144
149
145
150
test_expect_success ' run diff with -B -C (#9)' '
146
151
git diff-index -B -C reference >current &&
147
- cat >expect <<-\ EOF &&
148
- :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec C095 file0 file1
149
- :100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 69a939f651686f56322566e2fd76715947a24162 R095 file0 file2
152
+ cat >expect <<-EOF &&
153
+ :100644 100644 $blob0_id $blob2_id C095 file0 file1
154
+ :100644 100644 $blob0_id $blob3_id R095 file0 file2
150
155
EOF
151
156
compare_diff_raw expect current
152
157
'
0 commit comments