change script variable name to avoid collision with PATH in windows
[git/mingw/4msysgit/gitPS1fix.git] / t / t5407-post-rewrite-hook.sh
blob35403b435e9f6c1cc1cbbf019bbb520b4101538a
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 #!/usr/bin/perl
24 open (AR, ">$TRASH_DIRECTORY/post-rewrite.args");
25 print AR \$_,"\n" foreach @ARGV;
26 open (DAT, ">$TRASH_DIRECTORY/post-rewrite.data");
27 while(<STDIN>) {
28 print DAT;
30 EOF
31 chmod u+x .git/hooks/post-rewrite
33 clear_hook_input () {
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' '
43 clear_hook_input &&
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 &&
49 verify_hook_input
52 test_expect_success 'git commit --amend --no-post-rewrite' '
53 clear_hook_input &&
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' '
61 git reset --hard D &&
62 clear_hook_input &&
63 test_must_fail git rebase --onto A B &&
64 echo C > foo &&
65 git add foo &&
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)
71 EOF
72 verify_hook_input
75 test_expect_success 'git rebase --skip' '
76 git reset --hard D &&
77 clear_hook_input &&
78 test_must_fail git rebase --onto A B &&
79 test_must_fail git rebase --skip &&
80 echo D > foo &&
81 git add foo &&
82 git rebase --continue &&
83 echo rebase >expected.args &&
84 cat >expected.data <<EOF &&
85 $(git rev-parse D) $(git rev-parse HEAD)
86 EOF
87 verify_hook_input
90 test_expect_success 'git rebase --skip the last one' '
91 git reset --hard F &&
92 clear_hook_input &&
93 test_must_fail git rebase --onto D A &&
94 git rebase --skip &&
95 echo rebase >expected.args &&
96 cat >expected.data <<EOF &&
97 $(git rev-parse E) $(git rev-parse HEAD)
98 EOF
99 verify_hook_input
102 test_expect_success 'git rebase -m' '
103 git reset --hard D &&
104 clear_hook_input &&
105 test_must_fail git rebase -m --onto A B &&
106 echo C > foo &&
107 git add foo &&
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)
114 verify_hook_input
117 test_expect_success 'git rebase -m --skip' '
118 git reset --hard D &&
119 clear_hook_input &&
120 test_must_fail git rebase --onto A B &&
121 test_must_fail git rebase --skip &&
122 echo D > foo &&
123 git add foo &&
124 git rebase --continue &&
125 echo rebase >expected.args &&
126 cat >expected.data <<EOF &&
127 $(git rev-parse D) $(git rev-parse HEAD)
129 verify_hook_input
132 . "$TEST_DIRECTORY"/lib-rebase.sh
134 set_fake_editor
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 () {
140 FAKE_LINES="$1" &&
141 shift &&
142 export FAKE_LINES &&
143 test_must_fail git rebase -i "$@"
147 test_expect_success 'git rebase -i (unchanged)' '
148 git reset --hard D &&
149 clear_hook_input &&
150 test_fail_interactive_rebase "1 2" --onto A B &&
151 echo C > foo &&
152 git add foo &&
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)
159 verify_hook_input
162 test_expect_success 'git rebase -i (skip)' '
163 git reset --hard D &&
164 clear_hook_input &&
165 test_fail_interactive_rebase "2" --onto A B &&
166 echo D > foo &&
167 git add foo &&
168 git rebase --continue &&
169 echo rebase >expected.args &&
170 cat >expected.data <<EOF &&
171 $(git rev-parse D) $(git rev-parse HEAD)
173 verify_hook_input
176 test_expect_success 'git rebase -i (squash)' '
177 git reset --hard D &&
178 clear_hook_input &&
179 test_fail_interactive_rebase "1 squash 2" --onto A B &&
180 echo C > foo &&
181 git add foo &&
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)
188 verify_hook_input
191 test_expect_success 'git rebase -i (fixup without conflict)' '
192 git reset --hard D &&
193 clear_hook_input &&
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)
200 verify_hook_input
203 test_expect_success 'git rebase -i (double edit)' '
204 git reset --hard D &&
205 clear_hook_input &&
206 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
207 git rebase --continue &&
208 echo something > foo &&
209 git add 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)
216 verify_hook_input
219 test_done