partial-clone: avoid fetching when looking for objects
[git/debian.git] / t / t4027-diff-submodule.sh
blobe29deaf4a509523b00e6bf9ac5d2436957a1b022
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_oid_init &&
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-dirty &&
98 test_cmp expect.body actual.body
101 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' '
102 git commit -m "x" sub &&
103 echo >>sub/world &&
104 git diff HEAD >actual &&
105 sed -e "1,/^@@/d" actual >actual.body &&
106 expect_from_to >expect.body $subprev $subprev-dirty &&
107 test_cmp expect.body actual.body &&
108 git diff --ignore-submodules HEAD >actual2 &&
109 test_must_be_empty actual2 &&
110 git diff --ignore-submodules=untracked HEAD >actual3 &&
111 sed -e "1,/^@@/d" actual3 >actual3.body &&
112 expect_from_to >expect.body $subprev $subprev-dirty &&
113 test_cmp expect.body actual3.body &&
114 git diff --ignore-submodules=dirty HEAD >actual4 &&
115 test_must_be_empty actual4
118 test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' '
119 git config diff.ignoreSubmodules dirty &&
120 git diff HEAD >actual &&
121 test_must_be_empty actual &&
122 git config --add -f .gitmodules submodule.subname.ignore none &&
123 git config --add -f .gitmodules submodule.subname.path sub &&
124 git diff HEAD >actual &&
125 sed -e "1,/^@@/d" actual >actual.body &&
126 expect_from_to >expect.body $subprev $subprev-dirty &&
127 test_cmp expect.body actual.body &&
128 git config -f .gitmodules submodule.subname.ignore all &&
129 git config -f .gitmodules submodule.subname.path sub &&
130 git diff HEAD >actual2 &&
131 test_must_be_empty actual2 &&
132 git config -f .gitmodules submodule.subname.ignore untracked &&
133 git diff HEAD >actual3 &&
134 sed -e "1,/^@@/d" actual3 >actual3.body &&
135 expect_from_to >expect.body $subprev $subprev-dirty &&
136 test_cmp expect.body actual3.body &&
137 git config -f .gitmodules submodule.subname.ignore dirty &&
138 git diff HEAD >actual4 &&
139 test_must_be_empty actual4 &&
140 git config submodule.subname.ignore none &&
141 git config submodule.subname.path sub &&
142 git diff HEAD >actual &&
143 sed -e "1,/^@@/d" actual >actual.body &&
144 expect_from_to >expect.body $subprev $subprev-dirty &&
145 test_cmp expect.body actual.body &&
146 git config --remove-section submodule.subname &&
147 git config --remove-section -f .gitmodules submodule.subname &&
148 git config --unset diff.ignoreSubmodules &&
149 rm .gitmodules
152 test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
154 cd sub &&
155 git reset --hard &&
156 echo >>world &&
157 git add world
158 ) &&
159 git diff HEAD >actual &&
160 sed -e "1,/^@@/d" actual >actual.body &&
161 expect_from_to >expect.body $subprev $subprev-dirty &&
162 test_cmp expect.body actual.body
165 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' '
167 cd sub &&
168 git reset --hard &&
169 git clean -qfdx &&
170 >cruft
171 ) &&
172 git diff HEAD >actual &&
173 sed -e "1,/^@@/d" actual >actual.body &&
174 expect_from_to >expect.body $subprev $subprev-dirty &&
175 test_cmp expect.body actual.body &&
176 git diff --ignore-submodules=all HEAD >actual2 &&
177 test_must_be_empty actual2 &&
178 git diff --ignore-submodules=untracked HEAD >actual3 &&
179 test_must_be_empty actual3 &&
180 git diff --ignore-submodules=dirty HEAD >actual4 &&
181 test_must_be_empty actual4
184 test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' '
185 git config --add -f .gitmodules submodule.subname.ignore all &&
186 git config --add -f .gitmodules submodule.subname.path sub &&
187 git diff HEAD >actual2 &&
188 test_must_be_empty actual2 &&
189 git config -f .gitmodules submodule.subname.ignore untracked &&
190 git diff HEAD >actual3 &&
191 test_must_be_empty actual3 &&
192 git config -f .gitmodules submodule.subname.ignore dirty &&
193 git diff HEAD >actual4 &&
194 test_must_be_empty actual4 &&
195 git config submodule.subname.ignore none &&
196 git config submodule.subname.path sub &&
197 git diff HEAD >actual &&
198 sed -e "1,/^@@/d" actual >actual.body &&
199 expect_from_to >expect.body $subprev $subprev-dirty &&
200 test_cmp expect.body actual.body &&
201 git config --remove-section submodule.subname &&
202 git config --remove-section -f .gitmodules submodule.subname &&
203 rm .gitmodules
206 test_expect_success 'git diff between submodule commits' '
207 git diff HEAD^..HEAD >actual &&
208 sed -e "1,/^@@/d" actual >actual.body &&
209 expect_from_to >expect.body $subtip $subprev &&
210 test_cmp expect.body actual.body &&
211 git diff --ignore-submodules=dirty HEAD^..HEAD >actual &&
212 sed -e "1,/^@@/d" actual >actual.body &&
213 expect_from_to >expect.body $subtip $subprev &&
214 test_cmp expect.body actual.body &&
215 git diff --ignore-submodules HEAD^..HEAD >actual &&
216 test_must_be_empty actual
219 test_expect_success 'git diff between submodule commits [.gitmodules]' '
220 git diff HEAD^..HEAD >actual &&
221 sed -e "1,/^@@/d" actual >actual.body &&
222 expect_from_to >expect.body $subtip $subprev &&
223 test_cmp expect.body actual.body &&
224 git config --add -f .gitmodules submodule.subname.ignore dirty &&
225 git config --add -f .gitmodules submodule.subname.path sub &&
226 git diff HEAD^..HEAD >actual &&
227 sed -e "1,/^@@/d" actual >actual.body &&
228 expect_from_to >expect.body $subtip $subprev &&
229 test_cmp expect.body actual.body &&
230 git config -f .gitmodules submodule.subname.ignore all &&
231 git diff HEAD^..HEAD >actual &&
232 test_must_be_empty actual &&
233 git config submodule.subname.ignore dirty &&
234 git config submodule.subname.path sub &&
235 git diff HEAD^..HEAD >actual &&
236 sed -e "1,/^@@/d" actual >actual.body &&
237 expect_from_to >expect.body $subtip $subprev &&
238 git config --remove-section submodule.subname &&
239 git config --remove-section -f .gitmodules submodule.subname &&
240 rm .gitmodules
243 test_expect_success 'git diff (empty submodule dir)' '
244 rm -rf sub/* sub/.git &&
245 git diff > actual.empty &&
246 test_must_be_empty actual.empty
249 test_expect_success 'conflicted submodule setup' '
250 c=$(test_oid ff_1) &&
252 echo "000000 $ZERO_OID 0 sub" &&
253 echo "160000 1$c 1 sub" &&
254 echo "160000 2$c 2 sub" &&
255 echo "160000 3$c 3 sub"
256 ) | git update-index --index-info &&
257 echo >expect.nosub "diff --cc sub
258 index 2ffffff,3ffffff..0000000
259 --- a/sub
260 +++ b/sub
261 @@@ -1,1 -1,1 +1,1 @@@
262 - Subproject commit 2$c
263 -Subproject commit 3$c
264 ++Subproject commit $ZERO_OID" &&
266 hh=$(git rev-parse HEAD) &&
267 sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub
271 test_expect_success 'combined (empty submodule)' '
272 rm -fr sub && mkdir sub &&
273 git diff >actual &&
274 test_cmp expect.nosub actual
277 test_expect_success 'combined (with submodule)' '
278 rm -fr sub &&
279 git clone --no-checkout . sub &&
280 git diff >actual &&
281 test_cmp expect.withsub actual
286 test_done