SubmittingPatches: fix Asciidoc syntax in "GitHub CI" section
[alt-git.git] / t / t4027-diff-submodule.sh
blob94ef77e1dfedc28656d78c80b689eca6806a7b0c
1 #!/bin/sh
3 test_description='difference in submodules'
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-diff.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 $ZERO_OID M sub" >expect &&
35 subtip=$3 subprev=$2
38 test_expect_success 'git diff --raw HEAD' '
39 hexsz=$(test_oid hexsz) &&
40 git diff --raw --abbrev=$hexsz HEAD >actual &&
41 test_cmp expect actual
44 test_expect_success 'git diff-index --raw HEAD' '
45 git diff-index --raw HEAD >actual.index &&
46 test_cmp expect actual.index
49 test_expect_success 'git diff-files --raw' '
50 git diff-files --raw >actual.files &&
51 test_cmp expect actual.files
54 expect_from_to () {
55 printf "%sSubproject commit %s\n+Subproject commit %s\n" \
56 "-" "$1" "$2"
59 test_expect_success 'git diff HEAD' '
60 git diff HEAD >actual &&
61 sed -e "1,/^@@/d" actual >actual.body &&
62 expect_from_to >expect.body $subtip $subprev &&
63 test_cmp expect.body actual.body
66 test_expect_success 'git diff HEAD with dirty submodule (work tree)' '
67 echo >>sub/world &&
68 git diff HEAD >actual &&
69 sed -e "1,/^@@/d" actual >actual.body &&
70 expect_from_to >expect.body $subtip $subprev-dirty &&
71 test_cmp expect.body actual.body
74 test_expect_success 'git diff HEAD with dirty submodule (index)' '
76 cd sub &&
77 git reset --hard &&
78 echo >>world &&
79 git add world
80 ) &&
81 git diff HEAD >actual &&
82 sed -e "1,/^@@/d" actual >actual.body &&
83 expect_from_to >expect.body $subtip $subprev-dirty &&
84 test_cmp expect.body actual.body
87 test_expect_success 'git diff HEAD with dirty submodule (untracked)' '
89 cd sub &&
90 git reset --hard &&
91 git clean -qfdx &&
92 >cruft
93 ) &&
94 git diff HEAD >actual &&
95 sed -e "1,/^@@/d" actual >actual.body &&
96 expect_from_to >expect.body $subtip $subprev &&
97 test_cmp expect.body actual.body
100 test_expect_success 'git diff HEAD with dirty submodule (untracked) (none ignored)' '
101 test_config diff.ignoreSubmodules none &&
102 git diff HEAD >actual &&
103 sed -e "1,/^@@/d" actual >actual.body &&
104 expect_from_to >expect.body $subtip $subprev-dirty &&
105 test_cmp expect.body actual.body
108 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
109 git commit -m "x" sub &&
110 echo >>sub/world &&
111 git diff HEAD >actual &&
112 sed -e "1,/^@@/d" actual >actual.body &&
113 expect_from_to >expect.body $subprev $subprev-dirty &&
114 test_cmp expect.body actual.body &&
115 git diff --ignore-submodules HEAD >actual2 &&
116 test_must_be_empty actual2 &&
117 git diff --ignore-submodules=untracked HEAD >actual3 &&
118 sed -e "1,/^@@/d" actual3 >actual3.body &&
119 expect_from_to >expect.body $subprev $subprev-dirty &&
120 test_cmp expect.body actual3.body &&
121 git diff --ignore-submodules=dirty HEAD >actual4 &&
122 test_must_be_empty actual4
125 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
126 git config diff.ignoreSubmodules dirty &&
127 git diff HEAD >actual &&
128 test_must_be_empty actual &&
129 git config --add -f .gitmodules submodule.subname.ignore none &&
130 git config --add -f .gitmodules submodule.subname.path sub &&
131 git diff HEAD >actual &&
132 sed -e "1,/^@@/d" actual >actual.body &&
133 expect_from_to >expect.body $subprev $subprev-dirty &&
134 test_cmp expect.body actual.body &&
135 git config -f .gitmodules submodule.subname.ignore all &&
136 git config -f .gitmodules submodule.subname.path sub &&
137 git diff HEAD >actual2 &&
138 test_must_be_empty actual2 &&
139 git config -f .gitmodules submodule.subname.ignore untracked &&
140 git diff HEAD >actual3 &&
141 sed -e "1,/^@@/d" actual3 >actual3.body &&
142 expect_from_to >expect.body $subprev $subprev-dirty &&
143 test_cmp expect.body actual3.body &&
144 git config -f .gitmodules submodule.subname.ignore dirty &&
145 git diff HEAD >actual4 &&
146 test_must_be_empty actual4 &&
147 git config submodule.subname.ignore none &&
148 git config submodule.subname.path sub &&
149 git diff HEAD >actual &&
150 sed -e "1,/^@@/d" actual >actual.body &&
151 expect_from_to >expect.body $subprev $subprev-dirty &&
152 test_cmp expect.body actual.body &&
153 git config --remove-section submodule.subname &&
154 git config --remove-section -f .gitmodules submodule.subname &&
155 git config --unset diff.ignoreSubmodules &&
156 rm .gitmodules
159 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
161 cd sub &&
162 git reset --hard &&
163 echo >>world &&
164 git add world
165 ) &&
166 git diff HEAD >actual &&
167 sed -e "1,/^@@/d" actual >actual.body &&
168 expect_from_to >expect.body $subprev $subprev-dirty &&
169 test_cmp expect.body actual.body
172 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
174 cd sub &&
175 git reset --hard &&
176 git clean -qfdx &&
177 >cruft
178 ) &&
179 git diff --ignore-submodules=none HEAD >actual &&
180 sed -e "1,/^@@/d" actual >actual.body &&
181 expect_from_to >expect.body $subprev $subprev-dirty &&
182 test_cmp expect.body actual.body &&
183 git diff --ignore-submodules=all HEAD >actual2 &&
184 test_must_be_empty actual2 &&
185 git diff HEAD >actual3 &&
186 test_must_be_empty actual3 &&
187 git diff --ignore-submodules=dirty HEAD >actual4 &&
188 test_must_be_empty actual4
191 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
192 git config --add -f .gitmodules submodule.subname.ignore all &&
193 git config --add -f .gitmodules submodule.subname.path sub &&
194 git diff HEAD >actual2 &&
195 test_must_be_empty actual2 &&
196 git config -f .gitmodules submodule.subname.ignore untracked &&
197 git diff HEAD >actual3 &&
198 test_must_be_empty actual3 &&
199 git config -f .gitmodules submodule.subname.ignore dirty &&
200 git diff HEAD >actual4 &&
201 test_must_be_empty actual4 &&
202 git config submodule.subname.ignore none &&
203 git config submodule.subname.path sub &&
204 git diff HEAD >actual &&
205 sed -e "1,/^@@/d" actual >actual.body &&
206 expect_from_to >expect.body $subprev $subprev-dirty &&
207 test_cmp expect.body actual.body &&
208 git config --remove-section submodule.subname &&
209 git config --remove-section -f .gitmodules submodule.subname &&
210 rm .gitmodules
213 test_expect_success 'git diff between submodule commits' '
214 git diff HEAD^..HEAD >actual &&
215 sed -e "1,/^@@/d" actual >actual.body &&
216 expect_from_to >expect.body $subtip $subprev &&
217 test_cmp expect.body actual.body &&
218 git diff --ignore-submodules=dirty 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 diff --ignore-submodules HEAD^..HEAD >actual &&
223 test_must_be_empty actual
226 test_expect_success 'git diff between submodule commits [.gitmodules]' '
227 git diff HEAD^..HEAD >actual &&
228 sed -e "1,/^@@/d" actual >actual.body &&
229 expect_from_to >expect.body $subtip $subprev &&
230 test_cmp expect.body actual.body &&
231 git config --add -f .gitmodules submodule.subname.ignore dirty &&
232 git config --add -f .gitmodules 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 test_cmp expect.body actual.body &&
237 git config -f .gitmodules submodule.subname.ignore all &&
238 git diff HEAD^..HEAD >actual &&
239 test_must_be_empty actual &&
240 git config submodule.subname.ignore dirty &&
241 git config submodule.subname.path sub &&
242 git diff HEAD^..HEAD >actual &&
243 sed -e "1,/^@@/d" actual >actual.body &&
244 expect_from_to >expect.body $subtip $subprev &&
245 git config --remove-section submodule.subname &&
246 git config --remove-section -f .gitmodules submodule.subname &&
247 rm .gitmodules
250 test_expect_success 'git diff (empty submodule dir)' '
251 rm -rf sub/* sub/.git &&
252 git diff > actual.empty &&
253 test_must_be_empty actual.empty
256 test_expect_success 'conflicted submodule setup' '
257 c=$(test_oid ff_1) &&
259 echo "000000 $ZERO_OID 0 sub" &&
260 echo "160000 1$c 1 sub" &&
261 echo "160000 2$c 2 sub" &&
262 echo "160000 3$c 3 sub"
263 ) | git update-index --index-info &&
264 echo >expect.nosub "diff --cc sub
265 index 2ffffff,3ffffff..0000000
266 --- a/sub
267 +++ b/sub
268 @@@ -1,1 -1,1 +1,1 @@@
269 - Subproject commit 2$c
270 -Subproject commit 3$c
271 ++Subproject commit $ZERO_OID" &&
273 hh=$(git rev-parse HEAD) &&
274 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
278 test_expect_success 'combined (empty submodule)' '
279 rm -fr sub && mkdir sub &&
280 git diff >actual &&
281 test_cmp expect.nosub actual
284 test_expect_success 'combined (with submodule)' '
285 rm -fr sub &&
286 git clone --no-checkout . sub &&
287 git diff >actual &&
288 test_cmp expect.withsub actual
293 test_done