compat/fsmonitor/fsm-listen-darwin: add MacOS header files for FSEvent
[git/debian.git] / t / t4027-diff-submodule.sh
blob6cef0da982faa1fbb86696ca0275eb49c8224090
1 #!/bin/sh
3 test_description='difference in submodules'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-diff.sh
9 test_expect_success setup '
10 test_tick &&
11 test_create_repo sub &&
13 cd sub &&
14 echo hello >world &&
15 git add world &&
16 git commit -m submodule
17 ) &&
19 test_tick &&
20 echo frotz >nitfol &&
21 git add nitfol sub &&
22 git commit -m superproject &&
25 cd sub &&
26 echo goodbye >world &&
27 git add world &&
28 git commit -m "submodule #2"
29 ) &&
31 set x $(
32 cd sub &&
33 git rev-list HEAD
34 ) &&
35 echo ":160000 160000 $3 $ZERO_OID M sub" >expect &&
36 subtip=$3 subprev=$2
39 test_expect_success 'git diff --raw HEAD' '
40 hexsz=$(test_oid hexsz) &&
41 git diff --raw --abbrev=$hexsz HEAD >actual &&
42 test_cmp expect actual
45 test_expect_success 'git diff-index --raw HEAD' '
46 git diff-index --raw HEAD >actual.index &&
47 test_cmp expect actual.index
50 test_expect_success 'git diff-files --raw' '
51 git diff-files --raw >actual.files &&
52 test_cmp expect actual.files
55 expect_from_to () {
56 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
57 "-" "$1" "$2"
60 test_expect_success 'git diff HEAD' '
61 git diff HEAD >actual &&
62 sed -e "1,/^@@/d" actual >actual.body &&
63 expect_from_to >expect.body $subtip $subprev &&
64 test_cmp expect.body actual.body
67 test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
68 echo >>sub/world &&
69 git diff HEAD >actual &&
70 sed -e "1,/^@@/d" actual >actual.body &&
71 expect_from_to >expect.body $subtip $subprev-dirty &&
72 test_cmp expect.body actual.body
75 test_expect_success 'git diff HEAD with dirty submodule (index)' '
77 cd sub &&
78 git reset --hard &&
79 echo >>world &&
80 git add world
81 ) &&
82 git diff HEAD >actual &&
83 sed -e "1,/^@@/d" actual >actual.body &&
84 expect_from_to >expect.body $subtip $subprev-dirty &&
85 test_cmp expect.body actual.body
88 test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
90 cd sub &&
91 git reset --hard &&
92 git clean -qfdx &&
93 >cruft
94 ) &&
95 git diff HEAD >actual &&
96 sed -e "1,/^@@/d" actual >actual.body &&
97 expect_from_to >expect.body $subtip $subprev &&
98 test_cmp expect.body actual.body
101 test_expect_success 'git diff HEAD with dirty submodule (untracked) (none ignored)' '
102 test_config diff.ignoreSubmodules none &&
103 git diff HEAD >actual &&
104 sed -e "1,/^@@/d" actual >actual.body &&
105 expect_from_to >expect.body $subtip $subprev-dirty &&
106 test_cmp expect.body actual.body
109 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
110 git commit -m "x" sub &&
111 echo >>sub/world &&
112 git diff HEAD >actual &&
113 sed -e "1,/^@@/d" actual >actual.body &&
114 expect_from_to >expect.body $subprev $subprev-dirty &&
115 test_cmp expect.body actual.body &&
116 git diff --ignore-submodules HEAD >actual2 &&
117 test_must_be_empty actual2 &&
118 git diff --ignore-submodules=untracked HEAD >actual3 &&
119 sed -e "1,/^@@/d" actual3 >actual3.body &&
120 expect_from_to >expect.body $subprev $subprev-dirty &&
121 test_cmp expect.body actual3.body &&
122 git diff --ignore-submodules=dirty HEAD >actual4 &&
123 test_must_be_empty actual4
126 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
127 git config diff.ignoreSubmodules dirty &&
128 git diff HEAD >actual &&
129 test_must_be_empty actual &&
130 git config --add -f .gitmodules submodule.subname.ignore none &&
131 git config --add -f .gitmodules submodule.subname.path sub &&
132 git diff HEAD >actual &&
133 sed -e "1,/^@@/d" actual >actual.body &&
134 expect_from_to >expect.body $subprev $subprev-dirty &&
135 test_cmp expect.body actual.body &&
136 git config -f .gitmodules submodule.subname.ignore all &&
137 git config -f .gitmodules submodule.subname.path sub &&
138 git diff HEAD >actual2 &&
139 test_must_be_empty actual2 &&
140 git config -f .gitmodules submodule.subname.ignore untracked &&
141 git diff HEAD >actual3 &&
142 sed -e "1,/^@@/d" actual3 >actual3.body &&
143 expect_from_to >expect.body $subprev $subprev-dirty &&
144 test_cmp expect.body actual3.body &&
145 git config -f .gitmodules submodule.subname.ignore dirty &&
146 git diff HEAD >actual4 &&
147 test_must_be_empty actual4 &&
148 git config submodule.subname.ignore none &&
149 git config submodule.subname.path sub &&
150 git diff HEAD >actual &&
151 sed -e "1,/^@@/d" actual >actual.body &&
152 expect_from_to >expect.body $subprev $subprev-dirty &&
153 test_cmp expect.body actual.body &&
154 git config --remove-section submodule.subname &&
155 git config --remove-section -f .gitmodules submodule.subname &&
156 git config --unset diff.ignoreSubmodules &&
157 rm .gitmodules
160 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
162 cd sub &&
163 git reset --hard &&
164 echo >>world &&
165 git add world
166 ) &&
167 git diff HEAD >actual &&
168 sed -e "1,/^@@/d" actual >actual.body &&
169 expect_from_to >expect.body $subprev $subprev-dirty &&
170 test_cmp expect.body actual.body
173 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
175 cd sub &&
176 git reset --hard &&
177 git clean -qfdx &&
178 >cruft
179 ) &&
180 git diff --ignore-submodules=none HEAD >actual &&
181 sed -e "1,/^@@/d" actual >actual.body &&
182 expect_from_to >expect.body $subprev $subprev-dirty &&
183 test_cmp expect.body actual.body &&
184 git diff --ignore-submodules=all HEAD >actual2 &&
185 test_must_be_empty actual2 &&
186 git diff HEAD >actual3 &&
187 test_must_be_empty actual3 &&
188 git diff --ignore-submodules=dirty HEAD >actual4 &&
189 test_must_be_empty actual4
192 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
193 git config --add -f .gitmodules submodule.subname.ignore all &&
194 git config --add -f .gitmodules submodule.subname.path sub &&
195 git diff HEAD >actual2 &&
196 test_must_be_empty actual2 &&
197 git config -f .gitmodules submodule.subname.ignore untracked &&
198 git diff HEAD >actual3 &&
199 test_must_be_empty actual3 &&
200 git config -f .gitmodules submodule.subname.ignore dirty &&
201 git diff HEAD >actual4 &&
202 test_must_be_empty actual4 &&
203 git config submodule.subname.ignore none &&
204 git config submodule.subname.path sub &&
205 git diff HEAD >actual &&
206 sed -e "1,/^@@/d" actual >actual.body &&
207 expect_from_to >expect.body $subprev $subprev-dirty &&
208 test_cmp expect.body actual.body &&
209 git config --remove-section submodule.subname &&
210 git config --remove-section -f .gitmodules submodule.subname &&
211 rm .gitmodules
214 test_expect_success 'git diff between submodule commits' '
215 git diff HEAD^..HEAD >actual &&
216 sed -e "1,/^@@/d" actual >actual.body &&
217 expect_from_to >expect.body $subtip $subprev &&
218 test_cmp expect.body actual.body &&
219 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
220 sed -e "1,/^@@/d" actual >actual.body &&
221 expect_from_to >expect.body $subtip $subprev &&
222 test_cmp expect.body actual.body &&
223 git diff --ignore-submodules HEAD^..HEAD >actual &&
224 test_must_be_empty actual
227 test_expect_success 'git diff between submodule commits [.gitmodules]' '
228 git diff HEAD^..HEAD >actual &&
229 sed -e "1,/^@@/d" actual >actual.body &&
230 expect_from_to >expect.body $subtip $subprev &&
231 test_cmp expect.body actual.body &&
232 git config --add -f .gitmodules submodule.subname.ignore dirty &&
233 git config --add -f .gitmodules submodule.subname.path sub &&
234 git diff HEAD^..HEAD >actual &&
235 sed -e "1,/^@@/d" actual >actual.body &&
236 expect_from_to >expect.body $subtip $subprev &&
237 test_cmp expect.body actual.body &&
238 git config -f .gitmodules submodule.subname.ignore all &&
239 git diff HEAD^..HEAD >actual &&
240 test_must_be_empty actual &&
241 git config submodule.subname.ignore dirty &&
242 git config submodule.subname.path sub &&
243 git diff HEAD^..HEAD >actual &&
244 sed -e "1,/^@@/d" actual >actual.body &&
245 expect_from_to >expect.body $subtip $subprev &&
246 git config --remove-section submodule.subname &&
247 git config --remove-section -f .gitmodules submodule.subname &&
248 rm .gitmodules
251 test_expect_success 'git diff (empty submodule dir)' '
252 rm -rf sub/* sub/.git &&
253 git diff > actual.empty &&
254 test_must_be_empty actual.empty
257 test_expect_success 'conflicted submodule setup' '
258 c=$(test_oid ff_1) &&
260 echo "000000 $ZERO_OID 0 sub" &&
261 echo "160000 1$c 1 sub" &&
262 echo "160000 2$c 2 sub" &&
263 echo "160000 3$c 3 sub"
264 ) | git update-index --index-info &&
265 echo >expect.nosub "diff --cc sub
266 index 2ffffff,3ffffff..0000000
267 --- a/sub
268 +++ b/sub
269 @@@ -1,1 -1,1 +1,1 @@@
270 - Subproject commit 2$c
271 -Subproject commit 3$c
272 ++Subproject commit $ZERO_OID" &&
274 hh=$(git rev-parse HEAD) &&
275 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
279 test_expect_success 'combined (empty submodule)' '
280 rm -fr sub && mkdir sub &&
281 git diff >actual &&
282 test_cmp expect.nosub actual
285 test_expect_success 'combined (with submodule)' '
286 rm -fr sub &&
287 git clone --no-checkout . sub &&
288 git diff >actual &&
289 test_cmp expect.withsub actual
294 test_done