Merge branch 'np/index-pack-memsave' into maint
[git/kirr.git] / t / t5407-post-rewrite-hook.sh
blob552da65a61e8f78d40f8e19cfc5b73696ebcf283
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
16 mkdir .git/hooks
18 cat >.git/hooks/post-rewrite <<EOF
19 #!/bin/sh
20 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
21 cat > "$TRASH_DIRECTORY"/post-rewrite.data
22 EOF
23 chmod u+x .git/hooks/post-rewrite
25 clear_hook_input () {
26 rm -f post-rewrite.args post-rewrite.data
29 verify_hook_input () {
30 test_cmp "$TRASH_DIRECTORY"/post-rewrite.args expected.args &&
31 test_cmp "$TRASH_DIRECTORY"/post-rewrite.data expected.data
34 test_expect_success 'git commit --amend' '
35 clear_hook_input &&
36 echo "D new message" > newmsg &&
37 oldsha=$(git rev-parse HEAD^0) &&
38 git commit -Fnewmsg --amend &&
39 echo amend > expected.args &&
40 echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
41 verify_hook_input
44 test_expect_success 'git commit --amend --no-post-rewrite' '
45 clear_hook_input &&
46 echo "D new message again" > newmsg &&
47 git commit --no-post-rewrite -Fnewmsg --amend &&
48 test ! -f post-rewrite.args &&
49 test ! -f post-rewrite.data
52 test_expect_success 'git rebase' '
53 git reset --hard D &&
54 clear_hook_input &&
55 test_must_fail git rebase --onto A B &&
56 echo C > foo &&
57 git add foo &&
58 git rebase --continue &&
59 echo rebase >expected.args &&
60 cat >expected.data <<EOF &&
61 $(git rev-parse C) $(git rev-parse HEAD^)
62 $(git rev-parse D) $(git rev-parse HEAD)
63 EOF
64 verify_hook_input
67 test_expect_success 'git rebase --skip' '
68 git reset --hard D &&
69 clear_hook_input &&
70 test_must_fail git rebase --onto A B &&
71 test_must_fail git rebase --skip &&
72 echo D > foo &&
73 git add foo &&
74 git rebase --continue &&
75 echo rebase >expected.args &&
76 cat >expected.data <<EOF &&
77 $(git rev-parse D) $(git rev-parse HEAD)
78 EOF
79 verify_hook_input
82 test_expect_success 'git rebase -m' '
83 git reset --hard D &&
84 clear_hook_input &&
85 test_must_fail git rebase -m --onto A B &&
86 echo C > foo &&
87 git add foo &&
88 git rebase --continue &&
89 echo rebase >expected.args &&
90 cat >expected.data <<EOF &&
91 $(git rev-parse C) $(git rev-parse HEAD^)
92 $(git rev-parse D) $(git rev-parse HEAD)
93 EOF
94 verify_hook_input
97 test_expect_success 'git rebase -m --skip' '
98 git reset --hard D &&
99 clear_hook_input &&
100 test_must_fail git rebase --onto A B &&
101 test_must_fail git rebase --skip &&
102 echo D > foo &&
103 git add foo &&
104 git rebase --continue &&
105 echo rebase >expected.args &&
106 cat >expected.data <<EOF &&
107 $(git rev-parse D) $(git rev-parse HEAD)
109 verify_hook_input
112 . "$TEST_DIRECTORY"/lib-rebase.sh
114 set_fake_editor
116 # Helper to work around the lack of one-shot exporting for
117 # test_must_fail (as it is a shell function)
118 test_fail_interactive_rebase () {
120 FAKE_LINES="$1" &&
121 shift &&
122 export FAKE_LINES &&
123 test_must_fail git rebase -i "$@"
127 test_expect_success 'git rebase -i (unchanged)' '
128 git reset --hard D &&
129 clear_hook_input &&
130 test_fail_interactive_rebase "1 2" --onto A B &&
131 echo C > foo &&
132 git add foo &&
133 git rebase --continue &&
134 echo rebase >expected.args &&
135 cat >expected.data <<EOF &&
136 $(git rev-parse C) $(git rev-parse HEAD^)
137 $(git rev-parse D) $(git rev-parse HEAD)
139 verify_hook_input
142 test_expect_success 'git rebase -i (skip)' '
143 git reset --hard D &&
144 clear_hook_input &&
145 test_fail_interactive_rebase "2" --onto A B &&
146 echo D > foo &&
147 git add foo &&
148 git rebase --continue &&
149 echo rebase >expected.args &&
150 cat >expected.data <<EOF &&
151 $(git rev-parse D) $(git rev-parse HEAD)
153 verify_hook_input
156 test_expect_success 'git rebase -i (squash)' '
157 git reset --hard D &&
158 clear_hook_input &&
159 test_fail_interactive_rebase "1 squash 2" --onto A B &&
160 echo C > foo &&
161 git add foo &&
162 git rebase --continue &&
163 echo rebase >expected.args &&
164 cat >expected.data <<EOF &&
165 $(git rev-parse C) $(git rev-parse HEAD)
166 $(git rev-parse D) $(git rev-parse HEAD)
168 verify_hook_input
171 test_expect_success 'git rebase -i (fixup without conflict)' '
172 git reset --hard D &&
173 clear_hook_input &&
174 FAKE_LINES="1 fixup 2" git rebase -i B &&
175 echo rebase >expected.args &&
176 cat >expected.data <<EOF &&
177 $(git rev-parse C) $(git rev-parse HEAD)
178 $(git rev-parse D) $(git rev-parse HEAD)
180 verify_hook_input
183 test_expect_success 'git rebase -i (double edit)' '
184 git reset --hard D &&
185 clear_hook_input &&
186 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
187 git rebase --continue &&
188 echo something > foo &&
189 git add foo &&
190 git rebase --continue &&
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_done