1#!/bin/sh
   2test_description='pre-commit hook'
   4. ./test-lib.sh
   6test_expect_success 'with no hook' '
   8        echo "foo" > file &&
  10        git add file &&
  11        git commit -m "first"
  12'
  14test_expect_success '--no-verify with no hook' '
  16        echo "bar" > file &&
  18        git add file &&
  19        git commit --no-verify -m "bar"
  20'
  22# now install hook that always succeeds
  24HOOKDIR="$(git rev-parse --git-dir)/hooks"
  25HOOK="$HOOKDIR/pre-commit"
  26mkdir -p "$HOOKDIR"
  27cat > "$HOOK" <<EOF
  28#!/bin/sh
  29exit 0
  30EOF
  31chmod +x "$HOOK"
  32test_expect_success 'with succeeding hook' '
  34        echo "more" >> file &&
  36        git add file &&
  37        git commit -m "more"
  38'
  40test_expect_success '--no-verify with succeeding hook' '
  42        echo "even more" >> file &&
  44        git add file &&
  45        git commit --no-verify -m "even more"
  46'
  48# now a hook that fails
  50cat > "$HOOK" <<EOF
  51#!/bin/sh
  52exit 1
  53EOF
  54test_expect_success 'with failing hook' '
  56        echo "another" >> file &&
  58        git add file &&
  59        ! git commit -m "another"
  60'
  62test_expect_success '--no-verify with failing hook' '
  64        echo "stuff" >> file &&
  66        git add file &&
  67        git commit --no-verify -m "stuff"
  68'
  70chmod -x "$HOOK"
  72test_expect_success 'with non-executable hook' '
  73        echo "content" >> file &&
  75        git add file &&
  76        git commit -m "content"
  77'
  79test_expect_success '--no-verify with non-executable hook' '
  81        echo "more content" >> file &&
  83        git add file &&
  84        git commit --no-verify -m "more content"
  85'
  87test_done