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' '
59 test_must_fail git rebase --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 --skip' '
74 test_must_fail git rebase --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 D) $(git rev-parse HEAD)
86 test_expect_success
'git rebase --skip the last one' '
89 test_must_fail git rebase --onto D A &&
91 echo rebase >expected.args &&
92 cat >expected.data <<EOF &&
93 $(git rev-parse E) $(git rev-parse HEAD)
98 test_expect_success
'git rebase -m' '
101 test_must_fail git rebase -m --onto A B &&
104 git rebase --continue &&
105 echo rebase >expected.args &&
106 cat >expected.data <<EOF &&
107 $(git rev-parse C) $(git rev-parse HEAD^)
108 $(git rev-parse D) $(git rev-parse HEAD)
113 test_expect_success
'git rebase -m --skip' '
114 git reset --hard D &&
116 test_must_fail git rebase --onto A B &&
117 test_must_fail git rebase --skip &&
120 git rebase --continue &&
121 echo rebase >expected.args &&
122 cat >expected.data <<EOF &&
123 $(git rev-parse D) $(git rev-parse HEAD)
128 .
"$TEST_DIRECTORY"/lib-rebase.sh
132 # Helper to work around the lack of one-shot exporting for
133 # test_must_fail (as it is a shell function)
134 test_fail_interactive_rebase
() {
139 test_must_fail git rebase
-i "$@"
143 test_expect_success
'git rebase -i (unchanged)' '
144 git reset --hard D &&
146 test_fail_interactive_rebase "1 2" --onto A B &&
149 git rebase --continue &&
150 echo rebase >expected.args &&
151 cat >expected.data <<EOF &&
152 $(git rev-parse C) $(git rev-parse HEAD^)
153 $(git rev-parse D) $(git rev-parse HEAD)
158 test_expect_success
'git rebase -i (skip)' '
159 git reset --hard D &&
161 test_fail_interactive_rebase "2" --onto A B &&
164 git rebase --continue &&
165 echo rebase >expected.args &&
166 cat >expected.data <<EOF &&
167 $(git rev-parse D) $(git rev-parse HEAD)
172 test_expect_success
'git rebase -i (squash)' '
173 git reset --hard D &&
175 test_fail_interactive_rebase "1 squash 2" --onto A B &&
178 git rebase --continue &&
179 echo rebase >expected.args &&
180 cat >expected.data <<EOF &&
181 $(git rev-parse C) $(git rev-parse HEAD)
182 $(git rev-parse D) $(git rev-parse HEAD)
187 test_expect_success
'git rebase -i (fixup without conflict)' '
188 git reset --hard D &&
190 FAKE_LINES="1 fixup 2" git rebase -i B &&
191 echo rebase >expected.args &&
192 cat >expected.data <<EOF &&
193 $(git rev-parse C) $(git rev-parse HEAD)
194 $(git rev-parse D) $(git rev-parse HEAD)
199 test_expect_success
'git rebase -i (double edit)' '
200 git reset --hard D &&
202 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
203 git rebase --continue &&
204 echo something > foo &&
206 git rebase --continue &&
207 echo rebase >expected.args &&
208 cat >expected.data <<EOF &&
209 $(git rev-parse C) $(git rev-parse HEAD^)
210 $(git rev-parse D) $(git rev-parse HEAD)