Skip to content

Commit fb2afea

Browse files
committed
t5573, t7612: clean up after unexpected success of 'pull' and 'merge'
The previous steps added test_when_finished to tests that run 'git pull' or 'git merge' with expectation of success, so that the test after them can start from a known state even when their 'git pull' invocation unexpectedly fails. However, tests that run 'git pull' or 'git merge' expecting it not to succeed forgot to protect later tests the same way---if they unexpectedly succeed, the test after them would start from an unexpected state. Reset and checkout the initial commit after all these tests, whether they expect their invocations to succeed or fail. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f8ca20 commit fb2afea

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

t/t5573-pull-verify-signatures.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,36 @@ test_expect_success GPG 'create repositories with signed commits' '
4343
'
4444

4545
test_expect_success GPG 'pull unsigned commit with --verify-signatures' '
46+
test_when_finished "git reset --hard && git checkout initial" &&
4647
test_must_fail git pull --ff-only --verify-signatures unsigned 2>pullerror &&
4748
test_i18ngrep "does not have a GPG signature" pullerror
4849
'
4950

5051
test_expect_success GPG 'pull commit with bad signature with --verify-signatures' '
52+
test_when_finished "git reset --hard && git checkout initial" &&
5153
test_must_fail git pull --ff-only --verify-signatures bad 2>pullerror &&
5254
test_i18ngrep "has a bad GPG signature" pullerror
5355
'
5456

5557
test_expect_success GPG 'pull commit with untrusted signature with --verify-signatures' '
58+
test_when_finished "git reset --hard && git checkout initial" &&
5659
test_must_fail git pull --ff-only --verify-signatures untrusted 2>pullerror &&
5760
test_i18ngrep "has an untrusted GPG signature" pullerror
5861
'
5962

6063
test_expect_success GPG 'pull signed commit with --verify-signatures' '
61-
test_when_finished "git checkout initial" &&
64+
test_when_finished "git reset --hard && git checkout initial" &&
6265
git pull --verify-signatures signed >pulloutput &&
6366
test_i18ngrep "has a good GPG signature" pulloutput
6467
'
6568

6669
test_expect_success GPG 'pull commit with bad signature without verification' '
67-
test_when_finished "git checkout initial" &&
70+
test_when_finished "git reset --hard && git checkout initial" &&
6871
git pull --ff-only bad 2>pullerror
6972
'
7073

7174
test_expect_success GPG 'pull commit with bad signature with --no-verify-signatures' '
72-
test_when_finished "git checkout initial" &&
75+
test_when_finished "git reset --hard && git checkout initial" &&
7376
test_config merge.verifySignatures true &&
7477
test_config pull.verifySignatures true &&
7578
git pull --ff-only --no-verify-signatures bad 2>pullerror

t/t7612-merge-verify-signatures.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,64 +35,70 @@ test_expect_success GPG 'create signed commits' '
3535
'
3636

3737
test_expect_success GPG 'merge unsigned commit with verification' '
38+
test_when_finished "git reset --hard && git checkout initial" &&
3839
test_must_fail git merge --ff-only --verify-signatures side-unsigned 2>mergeerror &&
3940
test_i18ngrep "does not have a GPG signature" mergeerror
4041
'
4142

4243
test_expect_success GPG 'merge unsigned commit with merge.verifySignatures=true' '
44+
test_when_finished "git reset --hard && git checkout initial" &&
4345
test_config merge.verifySignatures true &&
4446
test_must_fail git merge --ff-only side-unsigned 2>mergeerror &&
4547
test_i18ngrep "does not have a GPG signature" mergeerror
4648
'
4749

4850
test_expect_success GPG 'merge commit with bad signature with verification' '
51+
test_when_finished "git reset --hard && git checkout initial" &&
4952
test_must_fail git merge --ff-only --verify-signatures $(cat forged.commit) 2>mergeerror &&
5053
test_i18ngrep "has a bad GPG signature" mergeerror
5154
'
5255

5356
test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true' '
57+
test_when_finished "git reset --hard && git checkout initial" &&
5458
test_config merge.verifySignatures true &&
5559
test_must_fail git merge --ff-only $(cat forged.commit) 2>mergeerror &&
5660
test_i18ngrep "has a bad GPG signature" mergeerror
5761
'
5862

5963
test_expect_success GPG 'merge commit with untrusted signature with verification' '
64+
test_when_finished "git reset --hard && git checkout initial" &&
6065
test_must_fail git merge --ff-only --verify-signatures side-untrusted 2>mergeerror &&
6166
test_i18ngrep "has an untrusted GPG signature" mergeerror
6267
'
6368

6469
test_expect_success GPG 'merge commit with untrusted signature with merge.verifySignatures=true' '
70+
test_when_finished "git reset --hard && git checkout initial" &&
6571
test_config merge.verifySignatures true &&
6672
test_must_fail git merge --ff-only side-untrusted 2>mergeerror &&
6773
test_i18ngrep "has an untrusted GPG signature" mergeerror
6874
'
6975

7076
test_expect_success GPG 'merge signed commit with verification' '
71-
test_when_finished "git checkout initial" &&
77+
test_when_finished "git reset --hard && git checkout initial" &&
7278
git merge --verbose --ff-only --verify-signatures side-signed >mergeoutput &&
7379
test_i18ngrep "has a good GPG signature" mergeoutput
7480
'
7581

7682
test_expect_success GPG 'merge signed commit with merge.verifySignatures=true' '
77-
test_when_finished "git checkout initial" &&
83+
test_when_finished "git reset --hard && git checkout initial" &&
7884
test_config merge.verifySignatures true &&
7985
git merge --verbose --ff-only side-signed >mergeoutput &&
8086
test_i18ngrep "has a good GPG signature" mergeoutput
8187
'
8288

8389
test_expect_success GPG 'merge commit with bad signature without verification' '
84-
test_when_finished "git checkout initial" &&
90+
test_when_finished "git reset --hard && git checkout initial" &&
8591
git merge $(cat forged.commit)
8692
'
8793

8894
test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=false' '
89-
test_when_finished "git checkout initial" &&
95+
test_when_finished "git reset --hard && git checkout initial" &&
9096
test_config merge.verifySignatures false &&
9197
git merge $(cat forged.commit)
9298
'
9399

94100
test_expect_success GPG 'merge commit with bad signature with merge.verifySignatures=true and --no-verify-signatures' '
95-
test_when_finished "git checkout initial" &&
101+
test_when_finished "git reset --hard && git checkout initial" &&
96102
test_config merge.verifySignatures true &&
97103
git merge --no-verify-signatures $(cat forged.commit)
98104
'

0 commit comments

Comments
 (0)