Browse Source
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>maint
Thomas Rast
15 years ago
committed by
Junio C Hamano
3 changed files with 92 additions and 1 deletions
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
#!/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 |
Loading…
Reference in new issue