rebase: invoke post-rewrite hook
[git.git] / t / t5407-post-rewrite-hook.sh
blob1ecaa4b580b2049a12fdc4ba80600bfbc802122f
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_done