2007-09-27 01:31:01 +04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Josh England
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test the post-checkout hook.'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
2018-12-30 00:37:58 +03:00
|
|
|
mkdir -p .git/hooks &&
|
|
|
|
write_script .git/hooks/post-checkout <<-\EOF &&
|
|
|
|
echo "$@" >.git/post-checkout.args
|
|
|
|
EOF
|
|
|
|
test_commit one &&
|
|
|
|
test_commit two &&
|
2018-12-30 00:37:59 +03:00
|
|
|
test_commit rebase-on-me &&
|
|
|
|
git reset --hard HEAD^ &&
|
2018-12-30 00:37:58 +03:00
|
|
|
test_commit three
|
2007-09-27 01:31:01 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '
|
2018-12-30 00:37:58 +03:00
|
|
|
test_when_finished "rm -f .git/post-checkout.args" &&
|
|
|
|
git checkout master &&
|
|
|
|
read old new flag <.git/post-checkout.args &&
|
2014-06-06 18:55:59 +04:00
|
|
|
test $old = $new && test $flag = 1
|
2007-09-27 01:31:01 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'post-checkout args are correct with git checkout -b ' '
|
2018-12-30 00:37:58 +03:00
|
|
|
test_when_finished "rm -f .git/post-checkout.args" &&
|
|
|
|
git checkout -b new1 &&
|
|
|
|
read old new flag <.git/post-checkout.args &&
|
2014-06-06 18:55:59 +04:00
|
|
|
test $old = $new && test $flag = 1
|
2007-09-27 01:31:01 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'post-checkout receives the right args with HEAD changed ' '
|
2018-12-30 00:37:58 +03:00
|
|
|
test_when_finished "rm -f .git/post-checkout.args" &&
|
|
|
|
git checkout two &&
|
|
|
|
read old new flag <.git/post-checkout.args &&
|
2014-06-06 18:55:59 +04:00
|
|
|
test $old != $new && test $flag = 1
|
2007-09-27 01:31:01 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'post-checkout receives the right args when not switching branches ' '
|
2018-12-30 00:37:58 +03:00
|
|
|
test_when_finished "rm -f .git/post-checkout.args" &&
|
|
|
|
git checkout master -- three.t &&
|
|
|
|
read old new flag <.git/post-checkout.args &&
|
2014-06-06 18:55:59 +04:00
|
|
|
test $old = $new && test $flag = 0
|
2007-09-27 01:31:01 +04:00
|
|
|
'
|
|
|
|
|
2018-12-30 00:37:59 +03:00
|
|
|
test_expect_success 'post-checkout is triggered on rebase' '
|
|
|
|
test_when_finished "rm -f .git/post-checkout.args" &&
|
|
|
|
git checkout -b rebase-test master &&
|
|
|
|
rm -f .git/post-checkout.args &&
|
|
|
|
git rebase rebase-on-me &&
|
|
|
|
read old new flag <.git/post-checkout.args &&
|
|
|
|
test $old != $new && test $flag = 1
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'post-checkout is triggered on rebase with fast-forward' '
|
|
|
|
test_when_finished "rm -f .git/post-checkout.args" &&
|
|
|
|
git checkout -b ff-rebase-test rebase-on-me^ &&
|
|
|
|
rm -f .git/post-checkout.args &&
|
|
|
|
git rebase rebase-on-me &&
|
|
|
|
read old new flag <.git/post-checkout.args &&
|
|
|
|
test $old != $new && test $flag = 1
|
|
|
|
'
|
|
|
|
|
2009-03-03 08:37:51 +03:00
|
|
|
test_expect_success 'post-checkout hook is triggered by clone' '
|
2018-12-30 00:37:58 +03:00
|
|
|
mkdir -p templates/hooks &&
|
|
|
|
write_script templates/hooks/post-checkout <<-\EOF &&
|
2019-02-08 14:32:33 +03:00
|
|
|
echo "$@" >"$GIT_DIR/post-checkout.args"
|
2018-12-30 00:37:58 +03:00
|
|
|
EOF
|
2009-03-03 08:37:51 +03:00
|
|
|
git clone --template=templates . clone3 &&
|
|
|
|
test -f clone3/.git/post-checkout.args
|
|
|
|
'
|
|
|
|
|
2007-09-27 01:31:01 +04:00
|
|
|
test_done
|