]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3428-rebase-signoff.sh
The third batch
[thirdparty/git.git] / t / t3428-rebase-signoff.sh
CommitLineData
9f79524a
GB
1#!/bin/sh
2
3test_description='git rebase --signoff
4
5This test runs git rebase --signoff and make sure that it works.
6'
7
8. ./test-lib.sh
a6c2654f 9. "$TEST_DIRECTORY"/lib-rebase.sh
9f79524a 10
aac1c6e8
PW
11test_expect_success 'setup' '
12 git commit --allow-empty -m "Initial empty commit" &&
13 test_commit first file a &&
a6c2654f
PW
14 test_commit second file &&
15 git checkout -b conflict-branch first &&
16 test_commit file-2 file-2 &&
17 test_commit conflict file &&
18 test_commit third file &&
aac1c6e8
PW
19
20 ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" &&
9f79524a 21
aac1c6e8
PW
22 # Expected commit message for initial commit after rebase --signoff
23 cat >expected-initial-signed <<-EOF &&
24 Initial empty commit
a852ec7f 25
aac1c6e8
PW
26 Signed-off-by: $ident
27 EOF
a852ec7f 28
aac1c6e8
PW
29 # Expected commit message after rebase --signoff
30 cat >expected-signed <<-EOF &&
31 first
9f79524a 32
aac1c6e8
PW
33 Signed-off-by: $ident
34 EOF
9f79524a 35
a6c2654f
PW
36 # Expected commit message after conflict resolution for rebase --signoff
37 cat >expected-signed-conflict <<-EOF &&
38 third
39
40 Signed-off-by: $ident
41
42 conflict
43
44 Signed-off-by: $ident
45
46 file-2
47
48 Signed-off-by: $ident
49
50 EOF
51
aac1c6e8
PW
52 # Expected commit message after rebase without --signoff (or with --no-signoff)
53 cat >expected-unsigned <<-EOF &&
54 first
55 EOF
9f79524a 56
aac1c6e8
PW
57 git config alias.rbs "rebase --signoff"
58'
9f79524a
GB
59
60# We configure an alias to do the rebase --signoff so that
61# on the next subtest we can show that --no-signoff overrides the alias
b4454d5a 62test_expect_success 'rebase --apply --signoff adds a sign-off line' '
a6c2654f
PW
63 test_must_fail git rbs --apply second third &&
64 git checkout --theirs file &&
65 git add file &&
66 git rebase --continue &&
67 git log --format=%B -n3 >actual &&
68 test_cmp expected-signed-conflict actual
9f79524a
GB
69'
70
71test_expect_success 'rebase --no-signoff does not add a sign-off line' '
72 git commit --amend -m "first" &&
73 git rbs --no-signoff HEAD^ &&
1ad81756 74 test_commit_message HEAD expected-unsigned
9f79524a
GB
75'
76
a852ec7f
PW
77test_expect_success 'rebase --exec --signoff adds a sign-off line' '
78 test_when_finished "rm exec" &&
a6c2654f 79 git rebase --exec "touch exec" --signoff first^ first &&
a852ec7f 80 test_path_is_file exec &&
1ad81756 81 test_commit_message HEAD expected-signed
a852ec7f
PW
82'
83
84test_expect_success 'rebase --root --signoff adds a sign-off line' '
a6c2654f 85 git checkout first &&
a852ec7f 86 git rebase --root --keep-empty --signoff &&
1ad81756
PW
87 test_commit_message HEAD^ expected-initial-signed &&
88 test_commit_message HEAD expected-signed
a852ec7f
PW
89'
90
a6c2654f
PW
91test_expect_success 'rebase -m --signoff adds a sign-off line' '
92 test_must_fail git rebase -m --signoff second third &&
93 git checkout --theirs file &&
94 git add file &&
95 GIT_EDITOR="sed -n /Conflicts:/,/^\\\$/p >actual" \
96 git rebase --continue &&
97 cat >expect <<-\EOF &&
98 # Conflicts:
99 # file
100
101 EOF
102 test_cmp expect actual &&
103 git log --format=%B -n3 >actual &&
104 test_cmp expected-signed-conflict actual
a852ec7f
PW
105'
106
a6c2654f
PW
107test_expect_success 'rebase -i --signoff adds a sign-off line when editing commit' '
108 (
109 set_fake_editor &&
110 FAKE_LINES="edit 1 edit 3 edit 2" \
111 git rebase -i --signoff first third
112 ) &&
113 echo a >a &&
114 git add a &&
115 test_must_fail git rebase --continue &&
116 git checkout --ours file &&
117 echo b >a &&
118 git add a file &&
119 git rebase --continue &&
120 echo c >a &&
121 git add a &&
122 git log --format=%B -n3 >actual &&
123 cat >expect <<-EOF &&
124 conflict
125
126 Signed-off-by: $ident
127
128 third
129
130 Signed-off-by: $ident
131
132 file-2
133
134 Signed-off-by: $ident
135
136 EOF
137 test_cmp expect actual
a852ec7f 138'
a6c2654f 139
9f79524a 140test_done