3 # Copyright (c) 2010 Thomas Rast
6 test_description='Test the post-rewrite hook.'
9 test_expect_success 'setup' '
10 test_commit A foo A &&
11 test_commit B foo B &&
12 test_commit C foo C &&
13 test_commit D foo D &&
15 test_commit E bar E &&
16 test_commit F foo F &&
22 cat >.git/hooks/post-rewrite <<EOF
24 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
25 cat > "$TRASH_DIRECTORY"/post-rewrite.data
27 chmod u+x .git/hooks/post-rewrite
30 rm -f post-rewrite.args post-rewrite.data
33 verify_hook_input () {
34 test_cmp expected.args "$TRASH_DIRECTORY"/post-rewrite.args &&
35 test_cmp expected.data "$TRASH_DIRECTORY"/post-rewrite.data
38 test_expect_success 'git commit --amend' '
40 echo "D new message" > newmsg &&
41 oldsha=$(git rev-parse HEAD^0) &&
42 git commit -Fnewmsg --amend &&
43 echo amend > expected.args &&
44 echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
48 test_expect_success 'git commit --amend --no-post-rewrite' '
50 echo "D new message again" > newmsg &&
51 git commit --no-post-rewrite -Fnewmsg --amend &&
52 test ! -f post-rewrite.args &&
53 test ! -f post-rewrite.data
56 test_expect_success 'git rebase --apply' '
59 test_must_fail git rebase --apply --onto A B &&
62 git rebase --continue &&
63 echo rebase >expected.args &&
64 cat >expected.data <<-EOF &&
65 $(git rev-parse C) $(git rev-parse HEAD^)
66 $(git rev-parse D) $(git rev-parse HEAD)
71 test_expect_success 'git rebase --apply --skip' '
74 test_must_fail git rebase --apply --onto A B &&
75 test_must_fail git rebase --skip &&
78 git rebase --continue &&
79 echo rebase >expected.args &&
80 cat >expected.data <<-EOF &&
81 $(git rev-parse C) $(git rev-parse HEAD^)
82 $(git rev-parse D) $(git rev-parse HEAD)
87 test_expect_success 'git rebase --apply --skip the last one' '
90 test_must_fail git rebase --apply --onto D A &&
92 echo rebase >expected.args &&
93 cat >expected.data <<-EOF &&
94 $(git rev-parse E) $(git rev-parse HEAD)
95 $(git rev-parse F) $(git rev-parse HEAD)
100 test_expect_success 'git rebase -m' '
101 git reset --hard D &&
103 test_must_fail git rebase -m --onto A B &&
106 git rebase --continue &&
107 echo rebase >expected.args &&
108 cat >expected.data <<-EOF &&
109 $(git rev-parse C) $(git rev-parse HEAD^)
110 $(git rev-parse D) $(git rev-parse HEAD)
115 test_expect_success 'git rebase -m --skip' '
116 git reset --hard D &&
118 test_must_fail git rebase -m --onto A B &&
119 test_must_fail git rebase --skip &&
122 git rebase --continue &&
123 echo rebase >expected.args &&
124 cat >expected.data <<-EOF &&
125 $(git rev-parse C) $(git rev-parse HEAD^)
126 $(git rev-parse D) $(git rev-parse HEAD)
131 test_expect_success 'git rebase with implicit use of merge backend' '
132 git reset --hard D &&
134 test_must_fail git rebase --keep-empty --onto A B &&
137 git rebase --continue &&
138 echo rebase >expected.args &&
139 cat >expected.data <<-EOF &&
140 $(git rev-parse C) $(git rev-parse HEAD^)
141 $(git rev-parse D) $(git rev-parse HEAD)
146 test_expect_success 'git rebase --skip with implicit use of merge backend' '
147 git reset --hard D &&
149 test_must_fail git rebase --keep-empty --onto A B &&
150 test_must_fail git rebase --skip &&
153 git rebase --continue &&
154 echo rebase >expected.args &&
155 cat >expected.data <<-EOF &&
156 $(git rev-parse C) $(git rev-parse HEAD^)
157 $(git rev-parse D) $(git rev-parse HEAD)
162 . "$TEST_DIRECTORY"/lib-rebase.sh
166 # Helper to work around the lack of one-shot exporting for
167 # test_must_fail (as it is a shell function)
168 test_fail_interactive_rebase () {
173 test_must_fail git rebase -i "$@"
177 test_expect_success 'git rebase -i (unchanged)' '
178 git reset --hard D &&
180 test_fail_interactive_rebase "1 2" --onto A B &&
183 git rebase --continue &&
184 echo rebase >expected.args &&
185 cat >expected.data <<-EOF &&
186 $(git rev-parse C) $(git rev-parse HEAD^)
187 $(git rev-parse D) $(git rev-parse HEAD)
192 test_expect_success 'git rebase -i (skip)' '
193 git reset --hard D &&
195 test_fail_interactive_rebase "2" --onto A B &&
198 git rebase --continue &&
199 echo rebase >expected.args &&
200 cat >expected.data <<-EOF &&
201 $(git rev-parse D) $(git rev-parse HEAD)
206 test_expect_success 'git rebase -i (squash)' '
207 git reset --hard D &&
209 test_fail_interactive_rebase "1 squash 2" --onto A B &&
212 git rebase --continue &&
213 echo rebase >expected.args &&
214 cat >expected.data <<-EOF &&
215 $(git rev-parse C) $(git rev-parse HEAD)
216 $(git rev-parse D) $(git rev-parse HEAD)
221 test_expect_success 'git rebase -i (fixup without conflict)' '
222 git reset --hard D &&
224 FAKE_LINES="1 fixup 2" git rebase -i B &&
225 echo rebase >expected.args &&
226 cat >expected.data <<-EOF &&
227 $(git rev-parse C) $(git rev-parse HEAD)
228 $(git rev-parse D) $(git rev-parse HEAD)
233 test_expect_success 'git rebase -i (double edit)' '
234 git reset --hard D &&
236 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
237 git rebase --continue &&
238 echo something > foo &&
240 git rebase --continue &&
241 echo rebase >expected.args &&
242 cat >expected.data <<-EOF &&
243 $(git rev-parse C) $(git rev-parse HEAD^)
244 $(git rev-parse D) $(git rev-parse HEAD)
249 test_expect_success 'git rebase -i (exec)' '
250 git reset --hard D &&
252 FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
253 echo something >bar &&
255 # Fails because of exec false
256 test_must_fail git rebase --continue &&
257 git rebase --continue &&
258 echo rebase >expected.args &&
259 cat >expected.data <<-EOF &&
260 $(git rev-parse C) $(git rev-parse HEAD^)
261 $(git rev-parse D) $(git rev-parse HEAD)