263
test_cmp expect sorted_err
264
'
265
266
+test_expect_success 'textual symref content should be checked (individual)' '
267
+ test_when_finished "rm -rf repo" &&
268
+ git init repo &&
269
+ branch_dir_prefix=.git/refs/heads &&
270
+ cd repo &&
271
+ test_commit default &&
272
+ mkdir -p "$branch_dir_prefix/a/b" &&
273
+
274
+ for good_referent in "refs/heads/branch" "HEAD"
275
+ do
276
+ printf "ref: %s\n" $good_referent >$branch_dir_prefix/branch-good &&
277
+ git refs verify 2>err &&
278
+ rm $branch_dir_prefix/branch-good &&
279
+ test_must_be_empty err || return 1
280
+ done &&
281
+
282
+ for bad_referent in "refs/heads/.branch" "refs/heads/~branch" "refs/heads/?branch"
283
+ do
284
+ printf "ref: %s\n" $bad_referent >$branch_dir_prefix/branch-bad &&
285
+ test_must_fail git refs verify 2>err &&
286
+ cat >expect <<-EOF &&
287
+ error: refs/heads/branch-bad: badReferentName: points to invalid refname '\''$bad_referent'\''
288
+ EOF
289
+ rm $branch_dir_prefix/branch-bad &&
290
+ test_cmp expect err || return 1
291
+ done &&
292
+
293
+ printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline &&
294
+ git refs verify 2>err &&
295
+ cat >expect <<-EOF &&
296
+ warning: refs/heads/branch-no-newline: refMissingNewline: misses LF at the end
297
+ EOF
298
+ rm $branch_dir_prefix/branch-no-newline &&
299
+ test_cmp expect err &&
300
+
301
+ printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 &&
302
+ git refs verify 2>err &&
303
+ cat >expect <<-EOF &&
304
+ warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end
305
+ warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines
306
+ EOF
307
+ rm $branch_dir_prefix/a/b/branch-trailing-1 &&
308
+ test_cmp expect err &&
309
+
310
+ printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 &&
311
+ git refs verify 2>err &&
312
+ cat >expect <<-EOF &&
313
+ warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines
314
+ EOF
315
+ rm $branch_dir_prefix/a/b/branch-trailing-2 &&
316
+ test_cmp expect err &&
317
+
318
+ printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 &&
319
+ git refs verify 2>err &&
320
+ cat >expect <<-EOF &&
321
+ warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines
322
+ EOF
323
+ rm $branch_dir_prefix/a/b/branch-trailing-3 &&
324
+ test_cmp expect err &&
325
+
326
+ printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated &&
327
+ git refs verify 2>err &&
328
+ cat >expect <<-EOF &&
329
+ warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end
330
+ warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines
331
+ EOF
332
+ rm $branch_dir_prefix/a/b/branch-complicated &&
333
+ test_cmp expect err
334
+'
335
+
336
+test_expect_success 'textual symref content should be checked (aggregate)' '
337
+ test_when_finished "rm -rf repo" &&
338
+ git init repo &&
339
+ branch_dir_prefix=.git/refs/heads &&
340
+ tag_dir_prefix=.git/refs/tags &&
341
+ cd repo &&
342
+ test_commit default &&
343
+ mkdir -p "$branch_dir_prefix/a/b" &&
344
+
345
+ printf "ref: refs/heads/branch\n" >$branch_dir_prefix/branch-good &&
346
+ printf "ref: HEAD\n" >$branch_dir_prefix/branch-head &&
347
+ printf "ref: refs/heads/branch" >$branch_dir_prefix/branch-no-newline-1 &&
348
+ printf "ref: refs/heads/branch " >$branch_dir_prefix/a/b/branch-trailing-1 &&
349
+ printf "ref: refs/heads/branch\n\n" >$branch_dir_prefix/a/b/branch-trailing-2 &&
350
+ printf "ref: refs/heads/branch \n" >$branch_dir_prefix/a/b/branch-trailing-3 &&
351
+ printf "ref: refs/heads/branch \n " >$branch_dir_prefix/a/b/branch-complicated &&
352
+ printf "ref: refs/heads/.branch\n" >$branch_dir_prefix/branch-bad-1 &&
353
+
354
+ test_must_fail git refs verify 2>err &&
355
+ cat >expect <<-EOF &&
356
+ error: refs/heads/branch-bad-1: badReferentName: points to invalid refname '\''refs/heads/.branch'\''
357
+ warning: refs/heads/a/b/branch-complicated: refMissingNewline: misses LF at the end
358
+ warning: refs/heads/a/b/branch-complicated: trailingRefContent: has trailing whitespaces or newlines
359
+ warning: refs/heads/a/b/branch-trailing-1: refMissingNewline: misses LF at the end
360
+ warning: refs/heads/a/b/branch-trailing-1: trailingRefContent: has trailing whitespaces or newlines
361
+ warning: refs/heads/a/b/branch-trailing-2: trailingRefContent: has trailing whitespaces or newlines
362
+ warning: refs/heads/a/b/branch-trailing-3: trailingRefContent: has trailing whitespaces or newlines
363
+ warning: refs/heads/branch-no-newline-1: refMissingNewline: misses LF at the end
364
+ EOF
365
+ sort err >sorted_err &&
366
+ test_cmp expect sorted_err
367
+'
368
+
369
test_expect_success 'ref content checks should work with worktrees' '
370
test_when_finished "rm -rf repo" &&
371
git init repo &&
416
warning: worktrees/worktree-1/refs/worktree/branch-no-newline: refMissingNewline: misses LF at the end
417
EOF
418
rm $worktree1_refdir_prefix/branch-no-newline &&
419
+ test_cmp expect err &&
420
+
421
+ printf "%s garbage" "$(git rev-parse HEAD)" >$worktree1_refdir_prefix/branch-garbage &&
422
+ git refs verify 2>err &&
423
+ cat >expect <<-EOF &&
424
+ warning: worktrees/worktree-1/refs/worktree/branch-garbage: trailingRefContent: has trailing garbage: '\'' garbage'\''
425
+ EOF
426
+ rm $worktree1_refdir_prefix/branch-garbage &&
427
test_cmp expect err
428
'
429