Sort howto documents in howto-index.txt
[git/gitweb.git] / t / t5407-post-rewrite-hook.sh
blobbaa670cea5d8a9d8b4b4578de69917fe76f71d46
1 #!/bin/sh
3 # Copyright (c) 2010 Thomas Rast
6 test_description='Test the post-rewrite hook.'
7 . ./test-lib.sh
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 &&
14 git checkout A^0 &&
15 test_commit E bar E &&
16 test_commit F foo F &&
17 git checkout master
20 mkdir .git/hooks
22 cat >.git/hooks/post-rewrite <<EOF
23 #!/bin/sh
24 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
25 cat > "$TRASH_DIRECTORY"/post-rewrite.data
26 EOF
27 chmod u+x .git/hooks/post-rewrite
29 clear_hook_input () {
30 rm -f post-rewrite.args post-rewrite.data
33 verify_hook_input () {
34 test_cmp "$TRASH_DIRECTORY"/post-rewrite.args expected.args &&
35 test_cmp "$TRASH_DIRECTORY"/post-rewrite.data expected.data
38 test_expect_success 'git commit --amend' '
39 clear_hook_input &&
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 &&
45 verify_hook_input
48 test_expect_success 'git commit --amend --no-post-rewrite' '
49 clear_hook_input &&
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' '
57 git reset --hard D &&
58 clear_hook_input &&
59 test_must_fail git rebase --onto A B &&
60 echo C > foo &&
61 git add foo &&
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)
67 EOF
68 verify_hook_input
71 test_expect_success 'git rebase --skip' '
72 git reset --hard D &&
73 clear_hook_input &&
74 test_must_fail git rebase --onto A B &&
75 test_must_fail git rebase --skip &&
76 echo D > foo &&
77 git add foo &&
78 git rebase --continue &&
79 echo rebase >expected.args &&
80 cat >expected.data <<EOF &&
81 $(git rev-parse D) $(git rev-parse HEAD)
82 EOF
83 verify_hook_input
86 test_expect_success 'git rebase --skip the last one' '
87 git reset --hard F &&
88 clear_hook_input &&
89 test_must_fail git rebase --onto D A &&
90 git rebase --skip &&
91 echo rebase >expected.args &&
92 cat >expected.data <<EOF &&
93 $(git rev-parse E) $(git rev-parse HEAD)
94 EOF
95 verify_hook_input
98 test_expect_success 'git rebase -m' '
99 git reset --hard D &&
100 clear_hook_input &&
101 test_must_fail git rebase -m --onto A B &&
102 echo C > foo &&
103 git add foo &&
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)
110 verify_hook_input
113 test_expect_success 'git rebase -m --skip' '
114 git reset --hard D &&
115 clear_hook_input &&
116 test_must_fail git rebase --onto A B &&
117 test_must_fail git rebase --skip &&
118 echo D > foo &&
119 git add foo &&
120 git rebase --continue &&
121 echo rebase >expected.args &&
122 cat >expected.data <<EOF &&
123 $(git rev-parse D) $(git rev-parse HEAD)
125 verify_hook_input
128 . "$TEST_DIRECTORY"/lib-rebase.sh
130 set_fake_editor
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 () {
136 FAKE_LINES="$1" &&
137 shift &&
138 export FAKE_LINES &&
139 test_must_fail git rebase -i "$@"
143 test_expect_success 'git rebase -i (unchanged)' '
144 git reset --hard D &&
145 clear_hook_input &&
146 test_fail_interactive_rebase "1 2" --onto A B &&
147 echo C > foo &&
148 git add foo &&
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)
155 verify_hook_input
158 test_expect_success 'git rebase -i (skip)' '
159 git reset --hard D &&
160 clear_hook_input &&
161 test_fail_interactive_rebase "2" --onto A B &&
162 echo D > foo &&
163 git add foo &&
164 git rebase --continue &&
165 echo rebase >expected.args &&
166 cat >expected.data <<EOF &&
167 $(git rev-parse D) $(git rev-parse HEAD)
169 verify_hook_input
172 test_expect_success 'git rebase -i (squash)' '
173 git reset --hard D &&
174 clear_hook_input &&
175 test_fail_interactive_rebase "1 squash 2" --onto A B &&
176 echo C > foo &&
177 git add foo &&
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)
184 verify_hook_input
187 test_expect_success 'git rebase -i (fixup without conflict)' '
188 git reset --hard D &&
189 clear_hook_input &&
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)
196 verify_hook_input
199 test_expect_success 'git rebase -i (double edit)' '
200 git reset --hard D &&
201 clear_hook_input &&
202 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
203 git rebase --continue &&
204 echo something > foo &&
205 git add 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)
212 verify_hook_input
215 test_done