Merge branch 'ew/empty-merge-with-dirty-index'
[git.git] / t / t4027-diff-submodule.sh
blob2ffd11a142d8c1d2f532f662951a27a90119a76e
1 #!/bin/sh
3 test_description='difference in submodules'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/diff-lib.sh
8 test_expect_success setup '
9 test_tick &&
10 test_create_repo sub &&
12 cd sub &&
13 echo hello >world &&
14 git add world &&
15 git commit -m submodule
16 ) &&
18 test_tick &&
19 echo frotz >nitfol &&
20 git add nitfol sub &&
21 git commit -m superproject &&
24 cd sub &&
25 echo goodbye >world &&
26 git add world &&
27 git commit -m "submodule #2"
28 ) &&
30 set x $(
31 cd sub &&
32 git rev-list HEAD
33 ) &&
34 echo ":160000 160000 $3 $_z40 M sub" >expect &&
35 subtip=$3 subprev=$2
38 test_expect_success 'git diff --raw HEAD' '
39 git diff --raw --abbrev=40 HEAD >actual &&
40 test_cmp expect actual
43 test_expect_success 'git diff-index --raw HEAD' '
44 git diff-index --raw HEAD >actual.index &&
45 test_cmp expect actual.index
48 test_expect_success 'git diff-files --raw' '
49 git diff-files --raw >actual.files &&
50 test_cmp expect actual.files
53 expect_from_to () {
54 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
55 "-" "$1" "$2"
58 test_expect_success 'git diff HEAD' '
59 git diff HEAD >actual &&
60 sed -e "1,/^@@/d" actual >actual.body &&
61 expect_from_to >expect.body $subtip $subprev &&
62 test_cmp expect.body actual.body
65 test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
66 echo >>sub/world &&
67 git diff HEAD >actual &&
68 sed -e "1,/^@@/d" actual >actual.body &&
69 expect_from_to >expect.body $subtip $subprev-dirty &&
70 test_cmp expect.body actual.body
73 test_expect_success 'git diff HEAD with dirty submodule (index)' '
75 cd sub &&
76 git reset --hard &&
77 echo >>world &&
78 git add world
79 ) &&
80 git diff HEAD >actual &&
81 sed -e "1,/^@@/d" actual >actual.body &&
82 expect_from_to >expect.body $subtip $subprev-dirty &&
83 test_cmp expect.body actual.body
86 test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
88 cd sub &&
89 git reset --hard &&
90 git clean -qfdx &&
91 >cruft
92 ) &&
93 git diff HEAD >actual &&
94 sed -e "1,/^@@/d" actual >actual.body &&
95 expect_from_to >expect.body $subtip $subprev-dirty &&
96 test_cmp expect.body actual.body
99 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
100 git commit -m "x" sub &&
101 echo >>sub/world &&
102 git diff HEAD >actual &&
103 sed -e "1,/^@@/d" actual >actual.body &&
104 expect_from_to >expect.body $subprev $subprev-dirty &&
105 test_cmp expect.body actual.body &&
106 git diff --ignore-submodules HEAD >actual2 &&
107 ! test -s actual2 &&
108 git diff --ignore-submodules=untracked HEAD >actual3 &&
109 sed -e "1,/^@@/d" actual3 >actual3.body &&
110 expect_from_to >expect.body $subprev $subprev-dirty &&
111 test_cmp expect.body actual3.body &&
112 git diff --ignore-submodules=dirty HEAD >actual4 &&
113 ! test -s actual4
116 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
117 git config diff.ignoreSubmodules dirty &&
118 git diff HEAD >actual &&
119 ! test -s actual &&
120 git config --add -f .gitmodules submodule.subname.ignore none &&
121 git config --add -f .gitmodules submodule.subname.path sub &&
122 git diff HEAD >actual &&
123 sed -e "1,/^@@/d" actual >actual.body &&
124 expect_from_to >expect.body $subprev $subprev-dirty &&
125 test_cmp expect.body actual.body &&
126 git config -f .gitmodules submodule.subname.ignore all &&
127 git config -f .gitmodules submodule.subname.path sub &&
128 git diff HEAD >actual2 &&
129 ! test -s actual2 &&
130 git config -f .gitmodules submodule.subname.ignore untracked &&
131 git diff HEAD >actual3 &&
132 sed -e "1,/^@@/d" actual3 >actual3.body &&
133 expect_from_to >expect.body $subprev $subprev-dirty &&
134 test_cmp expect.body actual3.body &&
135 git config -f .gitmodules submodule.subname.ignore dirty &&
136 git diff HEAD >actual4 &&
137 ! test -s actual4 &&
138 git config submodule.subname.ignore none &&
139 git config submodule.subname.path sub &&
140 git diff HEAD >actual &&
141 sed -e "1,/^@@/d" actual >actual.body &&
142 expect_from_to >expect.body $subprev $subprev-dirty &&
143 test_cmp expect.body actual.body &&
144 git config --remove-section submodule.subname &&
145 git config --remove-section -f .gitmodules submodule.subname &&
146 git config --unset diff.ignoreSubmodules &&
147 rm .gitmodules
150 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
152 cd sub &&
153 git reset --hard &&
154 echo >>world &&
155 git add world
156 ) &&
157 git diff HEAD >actual &&
158 sed -e "1,/^@@/d" actual >actual.body &&
159 expect_from_to >expect.body $subprev $subprev-dirty &&
160 test_cmp expect.body actual.body
163 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
165 cd sub &&
166 git reset --hard &&
167 git clean -qfdx &&
168 >cruft
169 ) &&
170 git diff HEAD >actual &&
171 sed -e "1,/^@@/d" actual >actual.body &&
172 expect_from_to >expect.body $subprev $subprev-dirty &&
173 test_cmp expect.body actual.body &&
174 git diff --ignore-submodules=all HEAD >actual2 &&
175 ! test -s actual2 &&
176 git diff --ignore-submodules=untracked HEAD >actual3 &&
177 ! test -s actual3 &&
178 git diff --ignore-submodules=dirty HEAD >actual4 &&
179 ! test -s actual4
182 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
183 git config --add -f .gitmodules submodule.subname.ignore all &&
184 git config --add -f .gitmodules submodule.subname.path sub &&
185 git diff HEAD >actual2 &&
186 ! test -s actual2 &&
187 git config -f .gitmodules submodule.subname.ignore untracked &&
188 git diff HEAD >actual3 &&
189 ! test -s actual3 &&
190 git config -f .gitmodules submodule.subname.ignore dirty &&
191 git diff HEAD >actual4 &&
192 ! test -s actual4 &&
193 git config submodule.subname.ignore none &&
194 git config submodule.subname.path sub &&
195 git diff HEAD >actual &&
196 sed -e "1,/^@@/d" actual >actual.body &&
197 expect_from_to >expect.body $subprev $subprev-dirty &&
198 test_cmp expect.body actual.body &&
199 git config --remove-section submodule.subname &&
200 git config --remove-section -f .gitmodules submodule.subname &&
201 rm .gitmodules
204 test_expect_success 'git diff between submodule commits' '
205 git diff HEAD^..HEAD >actual &&
206 sed -e "1,/^@@/d" actual >actual.body &&
207 expect_from_to >expect.body $subtip $subprev &&
208 test_cmp expect.body actual.body &&
209 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
210 sed -e "1,/^@@/d" actual >actual.body &&
211 expect_from_to >expect.body $subtip $subprev &&
212 test_cmp expect.body actual.body &&
213 git diff --ignore-submodules HEAD^..HEAD >actual &&
214 ! test -s actual
217 test_expect_success 'git diff between submodule commits [.gitmodules]' '
218 git diff HEAD^..HEAD >actual &&
219 sed -e "1,/^@@/d" actual >actual.body &&
220 expect_from_to >expect.body $subtip $subprev &&
221 test_cmp expect.body actual.body &&
222 git config --add -f .gitmodules submodule.subname.ignore dirty &&
223 git config --add -f .gitmodules submodule.subname.path sub &&
224 git diff HEAD^..HEAD >actual &&
225 sed -e "1,/^@@/d" actual >actual.body &&
226 expect_from_to >expect.body $subtip $subprev &&
227 test_cmp expect.body actual.body &&
228 git config -f .gitmodules submodule.subname.ignore all &&
229 git diff HEAD^..HEAD >actual &&
230 ! test -s actual &&
231 git config submodule.subname.ignore dirty &&
232 git config submodule.subname.path sub &&
233 git diff HEAD^..HEAD >actual &&
234 sed -e "1,/^@@/d" actual >actual.body &&
235 expect_from_to >expect.body $subtip $subprev &&
236 git config --remove-section submodule.subname &&
237 git config --remove-section -f .gitmodules submodule.subname &&
238 rm .gitmodules
241 test_expect_success 'git diff (empty submodule dir)' '
242 : >empty &&
243 rm -rf sub/* sub/.git &&
244 git diff > actual.empty &&
245 test_cmp empty actual.empty
248 test_expect_success 'conflicted submodule setup' '
250 # 39 efs
251 c=fffffffffffffffffffffffffffffffffffffff &&
253 echo "000000 $_z40 0 sub" &&
254 echo "160000 1$c 1 sub" &&
255 echo "160000 2$c 2 sub" &&
256 echo "160000 3$c 3 sub"
257 ) | git update-index --index-info &&
258 echo >expect.nosub '\''diff --cc sub
259 index 2ffffff,3ffffff..0000000
260 --- a/sub
261 +++ b/sub
262 @@@ -1,1 -1,1 +1,1 @@@
263 - Subproject commit 2fffffffffffffffffffffffffffffffffffffff
264 -Subproject commit 3fffffffffffffffffffffffffffffffffffffff
265 ++Subproject commit 0000000000000000000000000000000000000000'\'' &&
267 hh=$(git rev-parse HEAD) &&
268 sed -e "s/$_z40/$hh/" expect.nosub >expect.withsub
272 test_expect_success 'combined (empty submodule)' '
273 rm -fr sub && mkdir sub &&
274 git diff >actual &&
275 test_cmp expect.nosub actual
278 test_expect_success 'combined (with submodule)' '
279 rm -fr sub &&
280 git clone --no-checkout . sub &&
281 git diff >actual &&
282 test_cmp expect.withsub actual
287 test_done