176
git rev-parse sometag
177
'
178
179
+test_expect_success 'fetch --atomic works with a single branch' '
180
+ test_when_finished "rm -rf \"$D\"/atomic" &&
181
+
182
+ cd "$D" &&
183
+ git clone . atomic &&
184
+ git branch atomic-branch &&
185
+ oid=$(git rev-parse atomic-branch) &&
186
+ echo "$oid" >expected &&
187
+
188
+ git -C atomic fetch --atomic origin &&
189
+ git -C atomic rev-parse origin/atomic-branch >actual &&
190
+ test_cmp expected actual &&
191
+ test $oid = "$(git -C atomic rev-parse --verify FETCH_HEAD)"
192
+'
193
+
194
+test_expect_success 'fetch --atomic works with multiple branches' '
195
+ test_when_finished "rm -rf \"$D\"/atomic" &&
196
+
197
+ cd "$D" &&
198
+ git clone . atomic &&
199
+ git branch atomic-branch-1 &&
200
+ git branch atomic-branch-2 &&
201
+ git branch atomic-branch-3 &&
202
+ git rev-parse refs/heads/atomic-branch-1 refs/heads/atomic-branch-2 refs/heads/atomic-branch-3 >actual &&
203
+
204
+ git -C atomic fetch --atomic origin &&
205
+ git -C atomic rev-parse refs/remotes/origin/atomic-branch-1 refs/remotes/origin/atomic-branch-2 refs/remotes/origin/atomic-branch-3 >expected &&
206
+ test_cmp expected actual
207
+'
208
+
209
+test_expect_success 'fetch --atomic works with mixed branches and tags' '
210
+ test_when_finished "rm -rf \"$D\"/atomic" &&
211
+
212
+ cd "$D" &&
213
+ git clone . atomic &&
214
+ git branch atomic-mixed-branch &&
215
+ git tag atomic-mixed-tag &&
216
+ git rev-parse refs/heads/atomic-mixed-branch refs/tags/atomic-mixed-tag >actual &&
217
+
218
+ git -C atomic fetch --tags --atomic origin &&
219
+ git -C atomic rev-parse refs/remotes/origin/atomic-mixed-branch refs/tags/atomic-mixed-tag >expected &&
220
+ test_cmp expected actual
221
+'
222
+
223
+test_expect_success 'fetch --atomic prunes references' '
224
+ test_when_finished "rm -rf \"$D\"/atomic" &&
225
+
226
+ cd "$D" &&
227
+ git branch atomic-prune-delete &&
228
+ git clone . atomic &&
229
+ git branch --delete atomic-prune-delete &&
230
+ git branch atomic-prune-create &&
231
+ git rev-parse refs/heads/atomic-prune-create >actual &&
232
+
233
+ git -C atomic fetch --prune --atomic origin &&
234
+ test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-prune-delete &&
235
+ git -C atomic rev-parse refs/remotes/origin/atomic-prune-create >expected &&
236
+ test_cmp expected actual
237
+'
238
+
239
+test_expect_success 'fetch --atomic aborts with non-fast-forward update' '
240
+ test_when_finished "rm -rf \"$D\"/atomic" &&
241
+
242
+ cd "$D" &&
243
+ git branch atomic-non-ff &&
244
+ git clone . atomic &&
245
+ git rev-parse HEAD >actual &&
246
+
247
+ git branch atomic-new-branch &&
248
+ parent_commit=$(git rev-parse atomic-non-ff~) &&
249
+ git update-ref refs/heads/atomic-non-ff $parent_commit &&
250
+
251
+ test_must_fail git -C atomic fetch --atomic origin refs/heads/*:refs/remotes/origin/* &&
252
+ test_must_fail git -C atomic rev-parse refs/remotes/origin/atomic-new-branch &&
253
+ git -C atomic rev-parse refs/remotes/origin/atomic-non-ff >expected &&
254
+ test_cmp expected actual &&
255
+ test_must_be_empty atomic/.git/FETCH_HEAD
256
+'
257
+
258
+test_expect_success 'fetch --atomic executes a single reference transaction only' '
259
+ test_when_finished "rm -rf \"$D\"/atomic" &&
260
+
261
+ cd "$D" &&
262
+ git clone . atomic &&
263
+ git branch atomic-hooks-1 &&
264
+ git branch atomic-hooks-2 &&
265
+ head_oid=$(git rev-parse HEAD) &&
266
+
267
+ cat >expected <<-EOF &&
268
+ prepared
269
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1
270
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2
271
+ committed
272
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-1
273
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-2
274
+ EOF
275
+
276
+ rm -f atomic/actual &&
277
+ write_script atomic/.git/hooks/reference-transaction <<-\EOF &&
278
+ ( echo "$*" && cat ) >>actual
279
+ EOF
280
+
281
+ git -C atomic fetch --atomic origin &&
282
+ test_cmp expected atomic/actual
283
+'
284
+
285
+test_expect_success 'fetch --atomic aborts all reference updates if hook aborts' '
286
+ test_when_finished "rm -rf \"$D\"/atomic" &&
287
+
288
+ cd "$D" &&
289
+ git clone . atomic &&
290
+ git branch atomic-hooks-abort-1 &&
291
+ git branch atomic-hooks-abort-2 &&
292
+ git branch atomic-hooks-abort-3 &&
293
+ git tag atomic-hooks-abort &&
294
+ head_oid=$(git rev-parse HEAD) &&
295
+
296
+ cat >expected <<-EOF &&
297
+ prepared
298
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1
299
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2
300
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3
301
+ $ZERO_OID $head_oid refs/tags/atomic-hooks-abort
302
+ aborted
303
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-1
304
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-2
305
+ $ZERO_OID $head_oid refs/remotes/origin/atomic-hooks-abort-3
306
+ $ZERO_OID $head_oid refs/tags/atomic-hooks-abort
307
+ EOF
308
+
309
+ rm -f atomic/actual &&
310
+ write_script atomic/.git/hooks/reference-transaction <<-\EOF &&
311
+ ( echo "$*" && cat ) >>actual
312
+ exit 1
313
+ EOF
314
+
315
+ git -C atomic for-each-ref >expected-refs &&
316
+ test_must_fail git -C atomic fetch --tags --atomic origin &&
317
+ git -C atomic for-each-ref >actual-refs &&
318
+ test_cmp expected-refs actual-refs &&
319
+ test_must_be_empty atomic/.git/FETCH_HEAD
320
+'
321
+
322
+test_expect_success 'fetch --atomic --append appends to FETCH_HEAD' '
323
+ test_when_finished "rm -rf \"$D\"/atomic" &&
324
+
325
+ cd "$D" &&
326
+ git clone . atomic &&
327
+ oid=$(git rev-parse HEAD) &&
328
+
329
+ git branch atomic-fetch-head-1 &&
330
+ git -C atomic fetch --atomic origin atomic-fetch-head-1 &&
331
+ test_line_count = 1 atomic/.git/FETCH_HEAD &&
332
+
333
+ git branch atomic-fetch-head-2 &&
334
+ git -C atomic fetch --atomic --append origin atomic-fetch-head-2 &&
335
+ test_line_count = 2 atomic/.git/FETCH_HEAD &&
336
+ cp atomic/.git/FETCH_HEAD expected &&
337
+
338
+ write_script atomic/.git/hooks/reference-transaction <<-\EOF &&
339
+ exit 1
340
+ EOF
341
+
342
+ git branch atomic-fetch-head-3 &&
343
+ test_must_fail git -C atomic fetch --atomic --append origin atomic-fetch-head-3 &&
344
+ test_cmp expected atomic/.git/FETCH_HEAD
345
+'
346
+
347
test_expect_success '--refmap="" ignores configured refspec' '
348
cd "$TRASH_DIRECTORY" &&
349
git clone "$D" remote-refs &&