Merge branch 'l10n/zh_TW/220113' of github.com:l10n-tw/git-po
[alt-git.git] / t / t5407-post-rewrite-hook.sh
blob6da8d760e288dc4b4c75e661f99d2a4850320587
1 #!/bin/sh
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
10 . ./test-lib.sh
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 &&
17 git checkout A^0 &&
18 test_commit E bar E &&
19 test_commit F foo F &&
20 git checkout main
23 cat >.git/hooks/post-rewrite <<EOF
24 #!/bin/sh
25 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
26 cat > "$TRASH_DIRECTORY"/post-rewrite.data
27 EOF
28 chmod u+x .git/hooks/post-rewrite
30 clear_hook_input () {
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' '
40 clear_hook_input &&
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 &&
46 verify_hook_input
49 test_expect_success 'git commit --amend --no-post-rewrite' '
50 clear_hook_input &&
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' '
58 git reset --hard D &&
59 clear_hook_input &&
60 test_must_fail git rebase --apply --onto A B &&
61 echo C > foo &&
62 git add foo &&
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)
68 EOF
69 verify_hook_input
72 test_expect_success 'git rebase --apply --skip' '
73 git reset --hard D &&
74 clear_hook_input &&
75 test_must_fail git rebase --apply --onto A B &&
76 test_must_fail git rebase --skip &&
77 echo D > foo &&
78 git add foo &&
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)
84 EOF
85 verify_hook_input
88 test_expect_success 'git rebase --apply --skip the last one' '
89 git reset --hard F &&
90 clear_hook_input &&
91 test_must_fail git rebase --apply --onto D A &&
92 git rebase --skip &&
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)
97 EOF
98 verify_hook_input
101 test_expect_success 'git rebase -m' '
102 git reset --hard D &&
103 clear_hook_input &&
104 test_must_fail git rebase -m --onto A B &&
105 echo C > foo &&
106 git add foo &&
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)
113 verify_hook_input
116 test_expect_success 'git rebase -m --skip' '
117 git reset --hard D &&
118 clear_hook_input &&
119 test_must_fail git rebase -m --onto A B &&
120 test_must_fail git rebase --skip &&
121 echo D > foo &&
122 git add foo &&
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)
129 verify_hook_input
132 test_expect_success 'git rebase with implicit use of merge backend' '
133 git reset --hard D &&
134 clear_hook_input &&
135 test_must_fail git rebase --keep-empty --onto A B &&
136 echo C > foo &&
137 git add foo &&
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)
144 verify_hook_input
147 test_expect_success 'git rebase --skip with implicit use of merge backend' '
148 git reset --hard D &&
149 clear_hook_input &&
150 test_must_fail git rebase --keep-empty --onto A B &&
151 test_must_fail git rebase --skip &&
152 echo D > foo &&
153 git add foo &&
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)
160 verify_hook_input
163 . "$TEST_DIRECTORY"/lib-rebase.sh
165 set_fake_editor
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 () {
171 FAKE_LINES="$1" &&
172 shift &&
173 export FAKE_LINES &&
174 test_must_fail git rebase -i "$@"
178 test_expect_success 'git rebase -i (unchanged)' '
179 git reset --hard D &&
180 clear_hook_input &&
181 test_fail_interactive_rebase "1 2" --onto A B &&
182 echo C > foo &&
183 git add foo &&
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)
190 verify_hook_input
193 test_expect_success 'git rebase -i (skip)' '
194 git reset --hard D &&
195 clear_hook_input &&
196 test_fail_interactive_rebase "2" --onto A B &&
197 echo D > foo &&
198 git add foo &&
199 git rebase --continue &&
200 echo rebase >expected.args &&
201 cat >expected.data <<-EOF &&
202 $(git rev-parse D) $(git rev-parse HEAD)
204 verify_hook_input
207 test_expect_success 'git rebase -i (squash)' '
208 git reset --hard D &&
209 clear_hook_input &&
210 test_fail_interactive_rebase "1 squash 2" --onto A B &&
211 echo C > foo &&
212 git add foo &&
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)
219 verify_hook_input
222 test_expect_success 'git rebase -i (fixup without conflict)' '
223 git reset --hard D &&
224 clear_hook_input &&
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)
231 verify_hook_input
234 test_expect_success 'git rebase -i (double edit)' '
235 git reset --hard D &&
236 clear_hook_input &&
237 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
238 git rebase --continue &&
239 echo something > foo &&
240 git add 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)
247 verify_hook_input
250 test_expect_success 'git rebase -i (exec)' '
251 git reset --hard D &&
252 clear_hook_input &&
253 FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
254 echo something >bar &&
255 git add 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)
264 verify_hook_input
267 test_done