Merge branch 'ds/mailmap'
[git/debian.git] / t / t3435-rebase-gpg-sign.sh
blob5f8ba2c7399dc3d1cb5661097a3a3f0990624e77
1 #!/bin/sh
3 # Copyright (c) 2020 Doan Tran Cong Danh
6 test_description='test rebase --[no-]gpg-sign'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./test-lib.sh
12 . "$TEST_DIRECTORY/lib-rebase.sh"
13 . "$TEST_DIRECTORY/lib-gpg.sh"
15 if ! test_have_prereq GPG
16 then
17 skip_all='skip all test rebase --[no-]gpg-sign, gpg not available'
18 test_done
21 test_rebase_gpg_sign () {
22 local must_fail= will=will fake_editor=
23 if test "x$1" = "x!"
24 then
25 must_fail=test_must_fail
26 will="won't"
27 shift
29 conf=$1
30 shift
31 test_expect_success "rebase $* with commit.gpgsign=$conf $will sign commit" "
32 git reset two &&
33 git config commit.gpgsign $conf &&
34 set_fake_editor &&
35 FAKE_LINES='r 1 p 2' git rebase --force-rebase --root $* &&
36 $must_fail git verify-commit HEAD^ &&
37 $must_fail git verify-commit HEAD
41 test_expect_success 'setup' '
42 test_commit one &&
43 test_commit two &&
44 test_must_fail git verify-commit HEAD &&
45 test_must_fail git verify-commit HEAD^
48 test_expect_success 'setup: merge commit' '
49 test_commit fork-point &&
50 git switch -c side &&
51 test_commit three &&
52 git switch main &&
53 git merge --no-ff side &&
54 git tag merged
57 test_rebase_gpg_sign ! false
58 test_rebase_gpg_sign true
59 test_rebase_gpg_sign ! true --no-gpg-sign
60 test_rebase_gpg_sign ! true --gpg-sign --no-gpg-sign
61 test_rebase_gpg_sign false --no-gpg-sign --gpg-sign
62 test_rebase_gpg_sign true -i
63 test_rebase_gpg_sign ! true -i --no-gpg-sign
64 test_rebase_gpg_sign ! true -i --gpg-sign --no-gpg-sign
65 test_rebase_gpg_sign false -i --no-gpg-sign --gpg-sign
67 test_expect_failure 'rebase -p --no-gpg-sign override commit.gpgsign' '
68 test_when_finished "git clean -f" &&
69 git reset --hard merged &&
70 git config commit.gpgsign true &&
71 git rebase -p --no-gpg-sign --onto=one fork-point main &&
72 test_must_fail git verify-commit HEAD
75 test_expect_success 'rebase -r, merge strategy, --gpg-sign will sign commit' '
76 git reset --hard merged &&
77 test_unconfig commit.gpgsign &&
78 git rebase -fr --gpg-sign -s resolve --root &&
79 git verify-commit HEAD
82 test_expect_success 'rebase -r, merge strategy, commit.gpgsign=true will sign commit' '
83 git reset --hard merged &&
84 git config commit.gpgsign true &&
85 git rebase -fr -s resolve --root &&
86 git verify-commit HEAD
89 test_expect_success 'rebase -r, merge strategy, commit.gpgsign=false --gpg-sign will sign commit' '
90 git reset --hard merged &&
91 git config commit.gpgsign false &&
92 git rebase -fr --gpg-sign -s resolve --root &&
93 git verify-commit HEAD
96 test_expect_success "rebase -r, merge strategy, commit.gpgsign=true --no-gpg-sign won't sign commit" '
97 git reset --hard merged &&
98 git config commit.gpgsign true &&
99 git rebase -fr --no-gpg-sign -s resolve --root &&
100 test_must_fail git verify-commit HEAD
103 test_expect_success 'rebase -r --gpg-sign will sign commit' '
104 git reset --hard merged &&
105 test_unconfig commit.gpgsign &&
106 git rebase -fr --gpg-sign --root &&
107 git verify-commit HEAD
110 test_expect_success 'rebase -r with commit.gpgsign=true will sign commit' '
111 git reset --hard merged &&
112 git config commit.gpgsign true &&
113 git rebase -fr --root &&
114 git verify-commit HEAD
117 test_expect_success 'rebase -r --gpg-sign with commit.gpgsign=false will sign commit' '
118 git reset --hard merged &&
119 git config commit.gpgsign false &&
120 git rebase -fr --gpg-sign --root &&
121 git verify-commit HEAD
124 test_expect_success "rebase -r --no-gpg-sign with commit.gpgsign=true won't sign commit" '
125 git reset --hard merged &&
126 git config commit.gpgsign true &&
127 git rebase -fr --no-gpg-sign --root &&
128 test_must_fail git verify-commit HEAD
131 test_done