t / t7503-pre-commit-hook.shon commit Merge branch 'maint' (9b433e4)
   1#!/bin/sh
   2
   3test_description='pre-commit hook'
   4
   5. ./test-lib.sh
   6
   7test_expect_success "with no hook" \
   8        "echo 'foo' > file &&
   9         git add file &&
  10         git commit -m 'first'"
  11
  12test_expect_success "--no-verify with no hook" \
  13        "echo 'bar' > file &&
  14         git add file &&
  15         git commit --no-verify -m 'bar'"
  16
  17# now install hook that always succeeds
  18HOOKDIR="$(git rev-parse --git-dir)/hooks"
  19HOOK="$HOOKDIR/pre-commit"
  20mkdir -p "$HOOKDIR"
  21cat > "$HOOK" <<EOF
  22#!/bin/sh
  23exit 0
  24EOF
  25chmod +x "$HOOK"
  26
  27test_expect_success "with succeeding hook" \
  28        "echo 'more' >> file &&
  29         git add file &&
  30         git commit -m 'more'"
  31
  32test_expect_success "--no-verify with succeeding hook" \
  33        "echo 'even more' >> file &&
  34         git add file &&
  35         git commit --no-verify -m 'even more'"
  36
  37# now a hook that fails
  38cat > "$HOOK" <<EOF
  39#!/bin/sh
  40exit 1
  41EOF
  42
  43test_expect_failure "with failing hook" \
  44        "echo 'another' >> file &&
  45         git add file &&
  46         git commit -m 'another'"
  47
  48test_expect_success "--no-verify with failing hook" \
  49        "echo 'stuff' >> file &&
  50         git add file &&
  51         git commit --no-verify -m 'stuff'"
  52
  53chmod -x "$HOOK"
  54test_expect_success "with non-executable hook" \
  55        "echo 'content' >> file &&
  56         git add file &&
  57         git commit -m 'content'"
  58
  59test_expect_success "--no-verify with non-executable hook" \
  60        "echo 'more content' >> file &&
  61         git add file &&
  62         git commit --no-verify -m 'more content'"
  63
  64test_done