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 open (AR, ">$TRASH_DIRECTORY/post-rewrite.args");
25 print AR \$_,"\n" foreach @ARGV;
26 open (DAT, ">$TRASH_DIRECTORY/post-rewrite.data");
31 chmod u
+x .git
/hooks
/post-rewrite
34 rm -f post-rewrite.args post-rewrite.data
37 verify_hook_input
() {
38 test_cmp
"$TRASH_DIRECTORY"/post-rewrite.args expected.args
&&
39 test_cmp
"$TRASH_DIRECTORY"/post-rewrite.data expected.data
42 test_expect_success
'git commit --amend' '
44 echo "D new message" > newmsg &&
45 oldsha=$(git rev-parse HEAD^0) &&
46 git commit -Fnewmsg --amend &&
47 echo amend > expected.args &&
48 echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
52 test_expect_success
'git commit --amend --no-post-rewrite' '
54 echo "D new message again" > newmsg &&
55 git commit --no-post-rewrite -Fnewmsg --amend &&
56 test ! -f post-rewrite.args &&
57 test ! -f post-rewrite.data
60 test_expect_success
'git rebase' '
63 test_must_fail git rebase --onto A B &&
66 git rebase --continue &&
67 echo rebase >expected.args &&
68 cat >expected.data <<EOF &&
69 $(git rev-parse C) $(git rev-parse HEAD^)
70 $(git rev-parse D) $(git rev-parse HEAD)
75 test_expect_success
'git rebase --skip' '
78 test_must_fail git rebase --onto A B &&
79 test_must_fail git rebase --skip &&
82 git rebase --continue &&
83 echo rebase >expected.args &&
84 cat >expected.data <<EOF &&
85 $(git rev-parse D) $(git rev-parse HEAD)
90 test_expect_success
'git rebase --skip the last one' '
93 test_must_fail git rebase --onto D A &&
95 echo rebase >expected.args &&
96 cat >expected.data <<EOF &&
97 $(git rev-parse E) $(git rev-parse HEAD)
102 test_expect_success
'git rebase -m' '
103 git reset --hard D &&
105 test_must_fail git rebase -m --onto A B &&
108 git rebase --continue &&
109 echo rebase >expected.args &&
110 cat >expected.data <<EOF &&
111 $(git rev-parse C) $(git rev-parse HEAD^)
112 $(git rev-parse D) $(git rev-parse HEAD)
117 test_expect_success
'git rebase -m --skip' '
118 git reset --hard D &&
120 test_must_fail git rebase --onto A B &&
121 test_must_fail git rebase --skip &&
124 git rebase --continue &&
125 echo rebase >expected.args &&
126 cat >expected.data <<EOF &&
127 $(git rev-parse D) $(git rev-parse HEAD)
132 .
"$TEST_DIRECTORY"/lib-rebase.sh
136 # Helper to work around the lack of one-shot exporting for
137 # test_must_fail (as it is a shell function)
138 test_fail_interactive_rebase
() {
143 test_must_fail git rebase
-i "$@"
147 test_expect_success
'git rebase -i (unchanged)' '
148 git reset --hard D &&
150 test_fail_interactive_rebase "1 2" --onto A B &&
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_expect_success
'git rebase -i (skip)' '
163 git reset --hard D &&
165 test_fail_interactive_rebase "2" --onto A B &&
168 git rebase --continue &&
169 echo rebase >expected.args &&
170 cat >expected.data <<EOF &&
171 $(git rev-parse D) $(git rev-parse HEAD)
176 test_expect_success
'git rebase -i (squash)' '
177 git reset --hard D &&
179 test_fail_interactive_rebase "1 squash 2" --onto A B &&
182 git rebase --continue &&
183 echo rebase >expected.args &&
184 cat >expected.data <<EOF &&
185 $(git rev-parse C) $(git rev-parse HEAD)
186 $(git rev-parse D) $(git rev-parse HEAD)
191 test_expect_success
'git rebase -i (fixup without conflict)' '
192 git reset --hard D &&
194 FAKE_LINES="1 fixup 2" git rebase -i B &&
195 echo rebase >expected.args &&
196 cat >expected.data <<EOF &&
197 $(git rev-parse C) $(git rev-parse HEAD)
198 $(git rev-parse D) $(git rev-parse HEAD)
203 test_expect_success
'git rebase -i (double edit)' '
204 git reset --hard D &&
206 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
207 git rebase --continue &&
208 echo something > foo &&
210 git rebase --continue &&
211 echo rebase >expected.args &&
212 cat >expected.data <<EOF &&
213 $(git rev-parse C) $(git rev-parse HEAD^)
214 $(git rev-parse D) $(git rev-parse HEAD)