The eighteenth batch
[git.git] / t / t3428-rebase-signoff.sh
blob365436ebfc36415333d01bd231f7f89e5223477d
1 #!/bin/sh
3 test_description='git rebase --signoff
5 This test runs git rebase --signoff and make sure that it works.
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-rebase.sh
12 test_expect_success 'setup' '
13 git commit --allow-empty -m "Initial empty commit" &&
14 test_commit first file a &&
15 test_commit second file &&
16 git checkout -b conflict-branch first &&
17 test_commit file-2 file-2 &&
18 test_commit conflict file &&
19 test_commit third file &&
21 ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" &&
23 # Expected commit message for initial commit after rebase --signoff
24 cat >expected-initial-signed <<-EOF &&
25 Initial empty commit
27 Signed-off-by: $ident
28 EOF
30 # Expected commit message after rebase --signoff
31 cat >expected-signed <<-EOF &&
32 first
34 Signed-off-by: $ident
35 EOF
37 # Expected commit message after conflict resolution for rebase --signoff
38 cat >expected-signed-conflict <<-EOF &&
39 third
41 Signed-off-by: $ident
43 conflict
45 Signed-off-by: $ident
47 file-2
49 Signed-off-by: $ident
51 EOF
53 # Expected commit message after rebase without --signoff (or with --no-signoff)
54 cat >expected-unsigned <<-EOF &&
55 first
56 EOF
58 git config alias.rbs "rebase --signoff"
61 # We configure an alias to do the rebase --signoff so that
62 # on the next subtest we can show that --no-signoff overrides the alias
63 test_expect_success 'rebase --apply --signoff adds a sign-off line' '
64 test_must_fail git rbs --apply second third &&
65 git checkout --theirs file &&
66 git add file &&
67 git rebase --continue &&
68 git log --format=%B -n3 >actual &&
69 test_cmp expected-signed-conflict actual
72 test_expect_success 'rebase --no-signoff does not add a sign-off line' '
73 git commit --amend -m "first" &&
74 git rbs --no-signoff HEAD^ &&
75 test_commit_message HEAD expected-unsigned
78 test_expect_success 'rebase --exec --signoff adds a sign-off line' '
79 test_when_finished "rm exec" &&
80 git rebase --exec "touch exec" --signoff first^ first &&
81 test_path_is_file exec &&
82 test_commit_message HEAD expected-signed
85 test_expect_success 'rebase --root --signoff adds a sign-off line' '
86 git checkout first &&
87 git rebase --root --keep-empty --signoff &&
88 test_commit_message HEAD^ expected-initial-signed &&
89 test_commit_message HEAD expected-signed
92 test_expect_success 'rebase -m --signoff adds a sign-off line' '
93 test_must_fail git rebase -m --signoff second third &&
94 git checkout --theirs file &&
95 git add file &&
96 GIT_EDITOR="sed -n /Conflicts:/,/^\\\$/p >actual" \
97 git rebase --continue &&
98 cat >expect <<-\EOF &&
99 # Conflicts:
100 # file
103 test_cmp expect actual &&
104 git log --format=%B -n3 >actual &&
105 test_cmp expected-signed-conflict actual
108 test_expect_success 'rebase -i --signoff adds a sign-off line when editing commit' '
110 set_fake_editor &&
111 FAKE_LINES="edit 1 edit 3 edit 2" \
112 git rebase -i --signoff first third
113 ) &&
114 echo a >a &&
115 git add a &&
116 test_must_fail git rebase --continue &&
117 git checkout --ours file &&
118 echo b >a &&
119 git add a file &&
120 git rebase --continue &&
121 echo c >a &&
122 git add a &&
123 git log --format=%B -n3 >actual &&
124 cat >expect <<-EOF &&
125 conflict
127 Signed-off-by: $ident
129 third
131 Signed-off-by: $ident
133 file-2
135 Signed-off-by: $ident
138 test_cmp expect actual
141 test_done