3 # Copyright (c) 2010 Thomas Rast
6 test_description
='Test the post-rewrite hook.'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 test_expect_success
'setup' '
13 test_commit A foo A &&
14 test_commit B foo B &&
15 test_commit C foo C &&
16 test_commit D foo D &&
18 test_commit E bar E &&
19 test_commit F foo F &&
23 cat >.git
/hooks
/post-rewrite
<<EOF
25 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
26 cat > "$TRASH_DIRECTORY"/post-rewrite.data
28 chmod u
+x .git
/hooks
/post-rewrite
31 rm -f post-rewrite.args post-rewrite.data
34 verify_hook_input
() {
35 test_cmp expected.args
"$TRASH_DIRECTORY"/post-rewrite.args
&&
36 test_cmp expected.data
"$TRASH_DIRECTORY"/post-rewrite.data
39 test_expect_success
'git commit --amend' '
41 echo "D new message" > newmsg &&
42 oldsha=$(git rev-parse HEAD^0) &&
43 git commit -Fnewmsg --amend &&
44 echo amend > expected.args &&
45 echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
49 test_expect_success
'git commit --amend --no-post-rewrite' '
51 echo "D new message again" > newmsg &&
52 git commit --no-post-rewrite -Fnewmsg --amend &&
53 test ! -f post-rewrite.args &&
54 test ! -f post-rewrite.data
57 test_expect_success
'git rebase --apply' '
60 test_must_fail git rebase --apply --onto A B &&
63 git rebase --continue &&
64 echo rebase >expected.args &&
65 cat >expected.data <<-EOF &&
66 $(git rev-parse C) $(git rev-parse HEAD^)
67 $(git rev-parse D) $(git rev-parse HEAD)
72 test_expect_success
'git rebase --apply --skip' '
75 test_must_fail git rebase --apply --onto A B &&
76 test_must_fail git rebase --skip &&
79 git rebase --continue &&
80 echo rebase >expected.args &&
81 cat >expected.data <<-EOF &&
82 $(git rev-parse C) $(git rev-parse HEAD^)
83 $(git rev-parse D) $(git rev-parse HEAD)
88 test_expect_success
'git rebase --apply --skip the last one' '
91 test_must_fail git rebase --apply --onto D A &&
93 echo rebase >expected.args &&
94 cat >expected.data <<-EOF &&
95 $(git rev-parse E) $(git rev-parse HEAD)
96 $(git rev-parse F) $(git rev-parse HEAD)
101 test_expect_success
'git rebase -m' '
102 git reset --hard D &&
104 test_must_fail git rebase -m --onto A B &&
107 git rebase --continue &&
108 echo rebase >expected.args &&
109 cat >expected.data <<-EOF &&
110 $(git rev-parse C) $(git rev-parse HEAD^)
111 $(git rev-parse D) $(git rev-parse HEAD)
116 test_expect_success
'git rebase -m --skip' '
117 git reset --hard D &&
119 test_must_fail git rebase -m --onto A B &&
120 test_must_fail git rebase --skip &&
123 git rebase --continue &&
124 echo rebase >expected.args &&
125 cat >expected.data <<-EOF &&
126 $(git rev-parse C) $(git rev-parse HEAD^)
127 $(git rev-parse D) $(git rev-parse HEAD)
132 test_expect_success
'git rebase with implicit use of merge backend' '
133 git reset --hard D &&
135 test_must_fail git rebase --keep-empty --onto A B &&
138 git rebase --continue &&
139 echo rebase >expected.args &&
140 cat >expected.data <<-EOF &&
141 $(git rev-parse C) $(git rev-parse HEAD^)
142 $(git rev-parse D) $(git rev-parse HEAD)
147 test_expect_success
'git rebase --skip with implicit use of merge backend' '
148 git reset --hard D &&
150 test_must_fail git rebase --keep-empty --onto A B &&
151 test_must_fail git rebase --skip &&
154 git rebase --continue &&
155 echo rebase >expected.args &&
156 cat >expected.data <<-EOF &&
157 $(git rev-parse C) $(git rev-parse HEAD^)
158 $(git rev-parse D) $(git rev-parse HEAD)
163 .
"$TEST_DIRECTORY"/lib-rebase.sh
167 # Helper to work around the lack of one-shot exporting for
168 # test_must_fail (as it is a shell function)
169 test_fail_interactive_rebase
() {
174 test_must_fail git rebase
-i "$@"
178 test_expect_success
'git rebase -i (unchanged)' '
179 git reset --hard D &&
181 test_fail_interactive_rebase "1 2" --onto A B &&
184 git rebase --continue &&
185 echo rebase >expected.args &&
186 cat >expected.data <<-EOF &&
187 $(git rev-parse C) $(git rev-parse HEAD^)
188 $(git rev-parse D) $(git rev-parse HEAD)
193 test_expect_success
'git rebase -i (skip)' '
194 git reset --hard D &&
196 test_fail_interactive_rebase "2" --onto A B &&
199 git rebase --continue &&
200 echo rebase >expected.args &&
201 cat >expected.data <<-EOF &&
202 $(git rev-parse D) $(git rev-parse HEAD)
207 test_expect_success
'git rebase -i (squash)' '
208 git reset --hard D &&
210 test_fail_interactive_rebase "1 squash 2" --onto A B &&
213 git rebase --continue &&
214 echo rebase >expected.args &&
215 cat >expected.data <<-EOF &&
216 $(git rev-parse C) $(git rev-parse HEAD)
217 $(git rev-parse D) $(git rev-parse HEAD)
222 test_expect_success
'git rebase -i (fixup without conflict)' '
223 git reset --hard D &&
225 FAKE_LINES="1 fixup 2" git rebase -i B &&
226 echo rebase >expected.args &&
227 cat >expected.data <<-EOF &&
228 $(git rev-parse C) $(git rev-parse HEAD)
229 $(git rev-parse D) $(git rev-parse HEAD)
234 test_expect_success
'git rebase -i (double edit)' '
235 git reset --hard D &&
237 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
238 git rebase --continue &&
239 echo something > foo &&
241 git rebase --continue &&
242 echo rebase >expected.args &&
243 cat >expected.data <<-EOF &&
244 $(git rev-parse C) $(git rev-parse HEAD^)
245 $(git rev-parse D) $(git rev-parse HEAD)
250 test_expect_success
'git rebase -i (exec)' '
251 git reset --hard D &&
253 FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
254 echo something >bar &&
256 # Fails because of exec false
257 test_must_fail git rebase --continue &&
258 git rebase --continue &&
259 echo rebase >expected.args &&
260 cat >expected.data <<-EOF &&
261 $(git rev-parse C) $(git rev-parse HEAD^)
262 $(git rev-parse D) $(git rev-parse HEAD)