]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7503-pre-commit-hook.sh
t0060: Fix tests on Windows
[thirdparty/git.git] / t / t7503-pre-commit-hook.sh
CommitLineData
264474f2
WC
1#!/bin/sh
2
3test_description='pre-commit hook'
4
5. ./test-lib.sh
6
cf7e147c 7test_expect_success 'with no hook' '
264474f2 8
cf7e147c
WC
9 echo "foo" > file &&
10 git add file &&
11 git commit -m "first"
12
13'
14
15test_expect_success '--no-verify with no hook' '
16
17 echo "bar" > file &&
18 git add file &&
19 git commit --no-verify -m "bar"
20
21'
264474f2
WC
22
23# 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"
32
cf7e147c
WC
33test_expect_success 'with succeeding hook' '
34
35 echo "more" >> file &&
36 git add file &&
37 git commit -m "more"
264474f2 38
cf7e147c
WC
39'
40
41test_expect_success '--no-verify with succeeding hook' '
42
43 echo "even more" >> file &&
44 git add file &&
45 git commit --no-verify -m "even more"
46
47'
264474f2
WC
48
49# now a hook that fails
50cat > "$HOOK" <<EOF
51#!/bin/sh
52exit 1
53EOF
54
41ac414e 55test_expect_success 'with failing hook' '
cf7e147c
WC
56
57 echo "another" >> file &&
58 git add file &&
d492b31c 59 test_must_fail git commit -m "another"
264474f2 60
cf7e147c
WC
61'
62
63test_expect_success '--no-verify with failing hook' '
64
65 echo "stuff" >> file &&
66 git add file &&
67 git commit --no-verify -m "stuff"
68
69'
264474f2
WC
70
71chmod -x "$HOOK"
cf7e147c
WC
72test_expect_success 'with non-executable hook' '
73
74 echo "content" >> file &&
75 git add file &&
76 git commit -m "content"
77
78'
79
80test_expect_success '--no-verify with non-executable hook' '
81
82 echo "more content" >> file &&
83 git add file &&
84 git commit --no-verify -m "more content"
85
86'
264474f2
WC
87
88test_done