1
0
mirror of https://github.com/git/git.git synced 2024-11-11 12:30:12 +01:00
git/t/t5407-post-rewrite-hook.sh
Thomas Rast 6f6bee3ba9 commit --amend: invoke post-rewrite hook
The rough structure of run_rewrite_hook() comes from
run_receive_hook() in receive-pack.

We introduce a --no-post-rewrite option and use it to avoid the hook
when called from git-rebase -i 'edit'.  The next patch will add full
support in git-rebase, and we only want to invoke the hook once.

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

53 lines
1.1 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_done