t / t5403-post-checkout-hook.shon commit userdiff: add a builtin pattern for dts files (3c81760)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Josh England
   4#
   5
   6test_description='Test the post-checkout hook.'
   7. ./test-lib.sh
   8
   9test_expect_success setup '
  10        mkdir -p .git/hooks &&
  11        write_script .git/hooks/post-checkout <<-\EOF &&
  12        echo "$@" >.git/post-checkout.args
  13        EOF
  14        test_commit one &&
  15        test_commit two &&
  16        test_commit rebase-on-me &&
  17        git reset --hard HEAD^ &&
  18        test_commit three
  19'
  20
  21test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' '
  22        test_when_finished "rm -f .git/post-checkout.args" &&
  23        git checkout master &&
  24        read old new flag <.git/post-checkout.args &&
  25        test $old = $new && test $flag = 1
  26'
  27
  28test_expect_success 'post-checkout args are correct with git checkout -b ' '
  29        test_when_finished "rm -f .git/post-checkout.args" &&
  30        git checkout -b new1 &&
  31        read old new flag <.git/post-checkout.args &&
  32        test $old = $new && test $flag = 1
  33'
  34
  35test_expect_success 'post-checkout receives the right args with HEAD changed ' '
  36        test_when_finished "rm -f .git/post-checkout.args" &&
  37        git checkout two &&
  38        read old new flag <.git/post-checkout.args &&
  39        test $old != $new && test $flag = 1
  40'
  41
  42test_expect_success 'post-checkout receives the right args when not switching branches ' '
  43        test_when_finished "rm -f .git/post-checkout.args" &&
  44        git checkout master -- three.t &&
  45        read old new flag <.git/post-checkout.args &&
  46        test $old = $new && test $flag = 0
  47'
  48
  49test_expect_success 'post-checkout is triggered on rebase' '
  50        test_when_finished "rm -f .git/post-checkout.args" &&
  51        git checkout -b rebase-test master &&
  52        rm -f .git/post-checkout.args &&
  53        git rebase rebase-on-me &&
  54        read old new flag <.git/post-checkout.args &&
  55        test $old != $new && test $flag = 1
  56'
  57
  58test_expect_success 'post-checkout is triggered on rebase with fast-forward' '
  59        test_when_finished "rm -f .git/post-checkout.args" &&
  60        git checkout -b ff-rebase-test rebase-on-me^ &&
  61        rm -f .git/post-checkout.args &&
  62        git rebase rebase-on-me &&
  63        read old new flag <.git/post-checkout.args &&
  64        test $old != $new && test $flag = 1
  65'
  66
  67test_expect_success 'post-checkout hook is triggered by clone' '
  68        mkdir -p templates/hooks &&
  69        write_script templates/hooks/post-checkout <<-\EOF &&
  70        echo "$@" >"$GIT_DIR/post-checkout.args"
  71        EOF
  72        git clone --template=templates . clone3 &&
  73        test -f clone3/.git/post-checkout.args
  74'
  75
  76test_done