1
0
mirror of https://github.com/git/git.git synced 2024-11-11 12:19:40 +01:00
git/t/t5407-post-rewrite-hook.sh
Thomas Rast 96e19488f1 rebase: invoke post-rewrite hook
We have to deal with two separate code paths: a normal rebase, which
actually goes through git-am; and rebase {-m|-s}.

The only small issue with both is that they need to remember the
original sha1 across a possible conflict resolution.  rebase -m
already puts this information in $dotest/current, and we just
introduce a similar file for git-am.

Note that in git-am, the hook really only runs when coming from
git-rebase: the code path that sets the $dotest/original-commit file
is guarded by a test for $dotest/rebasing.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-03-12 21:55:39 -08:00

83 lines
1.8 KiB
Bash
Executable File

#!/bin/sh
#
# Copyright (c) 2010 Thomas Rast
#
test_description='Test the post-rewrite hook.'
. ./test-lib.sh
test_expect_success 'setup' '
test_commit A foo A &&
test_commit B foo B &&
test_commit C foo C &&
test_commit D foo D
'
mkdir .git/hooks
cat >.git/hooks/post-rewrite <<EOF
#!/bin/sh
echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
cat > "$TRASH_DIRECTORY"/post-rewrite.data
EOF
chmod u+x .git/hooks/post-rewrite
clear_hook_input () {
rm -f post-rewrite.args post-rewrite.data
}
verify_hook_input () {
test_cmp "$TRASH_DIRECTORY"/post-rewrite.args expected.args &&
test_cmp "$TRASH_DIRECTORY"/post-rewrite.data expected.data
}
test_expect_success 'git commit --amend' '
clear_hook_input &&
echo "D new message" > newmsg &&
oldsha=$(git rev-parse HEAD^0) &&
git commit -Fnewmsg --amend &&
echo amend > expected.args &&
echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
verify_hook_input
'
test_expect_success 'git commit --amend --no-post-rewrite' '
clear_hook_input &&
echo "D new message again" > newmsg &&
git commit --no-post-rewrite -Fnewmsg --amend &&
test ! -f post-rewrite.args &&
test ! -f post-rewrite.data
'
test_expect_success 'git rebase' '
git reset --hard D &&
clear_hook_input &&
test_must_fail git rebase --onto A B &&
echo C > foo &&
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse C) $(git rev-parse HEAD^)
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'
test_expect_success 'git rebase --skip' '
git reset --hard D &&
clear_hook_input &&
test_must_fail git rebase --onto A B &&
test_must_fail git rebase --skip &&
echo D > foo &&
git add foo &&
git rebase --continue &&
echo rebase >expected.args &&
cat >expected.data <<EOF &&
$(git rev-parse D) $(git rev-parse HEAD)
EOF
verify_hook_input
'
test_done