Skip to content

Commit cee683b

Browse files
ydroneaudgitster
authored andcommitted
t7600: use test_config to set/unset git config variables
Instead of using construct such as: test_when_finished "git config --unset <key>" git config <key> <value> uses test_config <key> <value> The latter takes care of removing <key> at the end of the test. Tests are modified to assume default configuration at entry, and to reset the modified configuration variables at the end. Test 'merge log message' was relying on the presence of option `--no-ff` in the configuration. With the option, git show -s --pretty=format:%b HEAD produces an empty line and without the option, it produces an empty file. The test is modified to check with and without `--no-ff` option. Signed-off-by: Yann Droneaud <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e023a31 commit cee683b

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

t/t7600-merge.sh

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ create_merge_msgs () {
5656
echo &&
5757
git log --no-merges ^HEAD c2 c3
5858
} >squash.1-5-9 &&
59-
echo >msg.nolog &&
59+
: >msg.nologff &&
60+
echo >msg.nolognoff &&
6061
{
6162
echo "* tag 'c3':" &&
6263
echo " commit 3" &&
@@ -244,8 +245,7 @@ test_expect_success 'merges with --ff-only' '
244245
test_expect_success 'merges with merge.ff=only' '
245246
git reset --hard c1 &&
246247
test_tick &&
247-
test_when_finished "git config --unset merge.ff" &&
248-
git config merge.ff only &&
248+
test_config merge.ff "only" &&
249249
test_must_fail git merge c2 &&
250250
test_must_fail git merge c3 &&
251251
test_must_fail git merge c2 c3 &&
@@ -336,7 +336,7 @@ test_debug 'git log --graph --decorate --oneline --all'
336336

337337
test_expect_success 'merge c1 with c2 (no-commit in config)' '
338338
git reset --hard c1 &&
339-
git config branch.master.mergeoptions "--no-commit" &&
339+
test_config branch.master.mergeoptions "--no-commit" &&
340340
git merge c2 &&
341341
verify_merge file result.1-5 &&
342342
verify_head $c1 &&
@@ -346,12 +346,11 @@ test_expect_success 'merge c1 with c2 (no-commit in config)' '
346346
test_debug 'git log --graph --decorate --oneline --all'
347347

348348
test_expect_success 'merge c1 with c2 (log in config)' '
349-
git config branch.master.mergeoptions "" &&
350349
git reset --hard c1 &&
351350
git merge --log c2 &&
352351
git show -s --pretty=tformat:%s%n%b >expect &&
353352
354-
git config branch.master.mergeoptions --log &&
353+
test_config branch.master.mergeoptions "--log" &&
355354
git reset --hard c1 &&
356355
git merge c2 &&
357356
git show -s --pretty=tformat:%s%n%b >actual &&
@@ -360,17 +359,12 @@ test_expect_success 'merge c1 with c2 (log in config)' '
360359
'
361360

362361
test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
363-
test_when_finished "git config --remove-section branch.master" &&
364-
test_when_finished "git config --remove-section merge" &&
365-
test_might_fail git config --remove-section branch.master &&
366-
test_might_fail git config --remove-section merge &&
367-
368362
git reset --hard c1 &&
369363
git merge c2 &&
370364
git show -s --pretty=tformat:%s%n%b >expect &&
371365
372-
git config branch.master.mergeoptions "--no-log" &&
373-
git config merge.log true &&
366+
test_config branch.master.mergeoptions "--no-log" &&
367+
test_config merge.log "true" &&
374368
git reset --hard c1 &&
375369
git merge c2 &&
376370
git show -s --pretty=tformat:%s%n%b >actual &&
@@ -380,7 +374,7 @@ test_expect_success 'merge c1 with c2 (log in config gets overridden)' '
380374

381375
test_expect_success 'merge c1 with c2 (squash in config)' '
382376
git reset --hard c1 &&
383-
git config branch.master.mergeoptions "--squash" &&
377+
test_config branch.master.mergeoptions "--squash" &&
384378
git merge c2 &&
385379
verify_merge file result.1-5 &&
386380
verify_head $c1 &&
@@ -392,7 +386,7 @@ test_debug 'git log --graph --decorate --oneline --all'
392386

393387
test_expect_success 'override config option -n with --summary' '
394388
git reset --hard c1 &&
395-
git config branch.master.mergeoptions "-n" &&
389+
test_config branch.master.mergeoptions "-n" &&
396390
test_tick &&
397391
git merge --summary c2 >diffstat.txt &&
398392
verify_merge file result.1-5 msg.1-5 &&
@@ -406,7 +400,7 @@ test_expect_success 'override config option -n with --summary' '
406400

407401
test_expect_success 'override config option -n with --stat' '
408402
git reset --hard c1 &&
409-
git config branch.master.mergeoptions "-n" &&
403+
test_config branch.master.mergeoptions "-n" &&
410404
test_tick &&
411405
git merge --stat c2 >diffstat.txt &&
412406
verify_merge file result.1-5 msg.1-5 &&
@@ -422,7 +416,7 @@ test_debug 'git log --graph --decorate --oneline --all'
422416

423417
test_expect_success 'override config option --stat' '
424418
git reset --hard c1 &&
425-
git config branch.master.mergeoptions "--stat" &&
419+
test_config branch.master.mergeoptions "--stat" &&
426420
test_tick &&
427421
git merge -n c2 >diffstat.txt &&
428422
verify_merge file result.1-5 msg.1-5 &&
@@ -438,7 +432,7 @@ test_debug 'git log --graph --decorate --oneline --all'
438432

439433
test_expect_success 'merge c1 with c2 (override --no-commit)' '
440434
git reset --hard c1 &&
441-
git config branch.master.mergeoptions "--no-commit" &&
435+
test_config branch.master.mergeoptions "--no-commit" &&
442436
test_tick &&
443437
git merge --commit c2 &&
444438
verify_merge file result.1-5 msg.1-5 &&
@@ -449,7 +443,7 @@ test_debug 'git log --graph --decorate --oneline --all'
449443

450444
test_expect_success 'merge c1 with c2 (override --squash)' '
451445
git reset --hard c1 &&
452-
git config branch.master.mergeoptions "--squash" &&
446+
test_config branch.master.mergeoptions "--squash" &&
453447
test_tick &&
454448
git merge --no-squash c2 &&
455449
verify_merge file result.1-5 msg.1-5 &&
@@ -460,7 +454,6 @@ test_debug 'git log --graph --decorate --oneline --all'
460454

461455
test_expect_success 'merge c0 with c1 (no-ff)' '
462456
git reset --hard c0 &&
463-
git config branch.master.mergeoptions "" &&
464457
test_tick &&
465458
git merge --no-ff c1 &&
466459
verify_merge file result.1 &&
@@ -471,33 +464,29 @@ test_debug 'git log --graph --decorate --oneline --all'
471464

472465
test_expect_success 'merge c0 with c1 (merge.ff=false)' '
473466
git reset --hard c0 &&
474-
git config merge.ff false &&
467+
test_config merge.ff "false" &&
475468
test_tick &&
476469
git merge c1 &&
477-
git config --remove-section merge &&
478470
verify_merge file result.1 &&
479471
verify_parents $c0 $c1
480472
'
481473
test_debug 'git log --graph --decorate --oneline --all'
482474

483475
test_expect_success 'combine branch.master.mergeoptions with merge.ff' '
484476
git reset --hard c0 &&
485-
git config branch.master.mergeoptions --ff &&
486-
git config merge.ff false &&
477+
test_config branch.master.mergeoptions "--ff" &&
478+
test_config merge.ff "false" &&
487479
test_tick &&
488480
git merge c1 &&
489-
git config --remove-section "branch.master" &&
490-
git config --remove-section "merge" &&
491481
verify_merge file result.1 &&
492482
verify_parents "$c0"
493483
'
494484

495485
test_expect_success 'tolerate unknown values for merge.ff' '
496486
git reset --hard c0 &&
497-
git config merge.ff something-new &&
487+
test_config merge.ff "something-new" &&
498488
test_tick &&
499489
git merge c1 2>message &&
500-
git config --remove-section "merge" &&
501490
verify_head "$c1" &&
502491
test_cmp empty message
503492
'
@@ -515,7 +504,7 @@ test_expect_success 'combining --ff-only and --no-ff is refused' '
515504

516505
test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
517506
git reset --hard c0 &&
518-
git config branch.master.mergeoptions "--no-ff" &&
507+
test_config branch.master.mergeoptions "--no-ff" &&
519508
git merge --ff c1 &&
520509
verify_merge file result.1 &&
521510
verify_head $c1
@@ -525,14 +514,20 @@ test_expect_success 'merge log message' '
525514
git reset --hard c0 &&
526515
git merge --no-log c2 &&
527516
git show -s --pretty=format:%b HEAD >msg.act &&
528-
test_cmp msg.nolog msg.act &&
517+
test_cmp msg.nologff msg.act &&
518+
519+
git reset --hard c0 &&
520+
test_config branch.master.mergeoptions "--no-ff" &&
521+
git merge --no-log c2 &&
522+
git show -s --pretty=format:%b HEAD >msg.act &&
523+
test_cmp msg.nolognoff msg.act &&
529524
530525
git merge --log c3 &&
531526
git show -s --pretty=format:%b HEAD >msg.act &&
532527
test_cmp msg.log msg.act &&
533528
534529
git reset --hard HEAD^ &&
535-
git config merge.log yes &&
530+
test_config merge.log "yes" &&
536531
git merge c3 &&
537532
git show -s --pretty=format:%b HEAD >msg.act &&
538533
test_cmp msg.log msg.act
@@ -542,7 +537,6 @@ test_debug 'git log --graph --decorate --oneline --all'
542537

543538
test_expect_success 'merge c1 with c0, c2, c0, and c1' '
544539
git reset --hard c1 &&
545-
git config branch.master.mergeoptions "" &&
546540
test_tick &&
547541
git merge c0 c2 c0 c1 &&
548542
verify_merge file result.1-5 &&
@@ -553,7 +547,6 @@ test_debug 'git log --graph --decorate --oneline --all'
553547

554548
test_expect_success 'merge c1 with c0, c2, c0, and c1' '
555549
git reset --hard c1 &&
556-
git config branch.master.mergeoptions "" &&
557550
test_tick &&
558551
git merge c0 c2 c0 c1 &&
559552
verify_merge file result.1-5 &&
@@ -564,7 +557,6 @@ test_debug 'git log --graph --decorate --oneline --all'
564557

565558
test_expect_success 'merge c1 with c1 and c2' '
566559
git reset --hard c1 &&
567-
git config branch.master.mergeoptions "" &&
568560
test_tick &&
569561
git merge c1 c2 &&
570562
verify_merge file result.1-5 &&

0 commit comments

Comments
 (0)