Merge branch 'next' of git://repo.or.cz/alt-git
[git/mingw.git] / t / t7504-commit-msg-hook.sh
blob14cdce706b8ca7db2206a1e3bfd13f33599c8d75
1 #!/bin/sh
3 test_description='commit-msg hook'
5 . ./test-lib.sh
7 test_expect_success 'with no hook' '
9 echo "foo" > file &&
10 git add file &&
11 git commit -m "first"
15 # set up fake editor for interactive editing
16 cat > fake-editor <<'EOF'
17 #!/bin/sh
18 cp FAKE_MSG "$1"
19 exit 0
20 EOF
21 chmod +x fake-editor
22 FAKE_EDITOR="$(pwd)/fake-editor"
23 export FAKE_EDITOR
25 test_expect_success 'with no hook (editor)' '
27 echo "more foo" >> file &&
28 git add file &&
29 echo "more foo" > FAKE_MSG &&
30 GIT_EDITOR="$FAKE_EDITOR" git commit
34 test_expect_success '--no-verify with no hook' '
36 echo "bar" > file &&
37 git add file &&
38 git commit --no-verify -m "bar"
42 test_expect_success '--no-verify with no hook (editor)' '
44 echo "more bar" > file &&
45 git add file &&
46 echo "more bar" > FAKE_MSG &&
47 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
51 # now install hook that always succeeds
52 HOOKDIR="$(git rev-parse --git-dir)/hooks"
53 HOOK="$HOOKDIR/commit-msg"
54 mkdir -p "$HOOKDIR"
55 cat > "$HOOK" <<EOF
56 #!/bin/sh
57 exit 0
58 EOF
59 chmod +x "$HOOK"
61 test_expect_success 'with succeeding hook' '
63 echo "more" >> file &&
64 git add file &&
65 git commit -m "more"
69 test_expect_success 'with succeeding hook (editor)' '
71 echo "more more" >> file &&
72 git add file &&
73 echo "more more" > FAKE_MSG &&
74 GIT_EDITOR="$FAKE_EDITOR" git commit
78 test_expect_success '--no-verify with succeeding hook' '
80 echo "even more" >> file &&
81 git add file &&
82 git commit --no-verify -m "even more"
86 test_expect_success '--no-verify with succeeding hook (editor)' '
88 echo "even more more" >> file &&
89 git add file &&
90 echo "even more more" > FAKE_MSG &&
91 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
95 # now a hook that fails
96 cat > "$HOOK" <<EOF
97 #!/bin/sh
98 exit 1
99 EOF
101 test_expect_success 'with failing hook' '
103 echo "another" >> file &&
104 git add file &&
105 ! git commit -m "another"
109 test_expect_success 'with failing hook (editor)' '
111 echo "more another" >> file &&
112 git add file &&
113 echo "more another" > FAKE_MSG &&
114 ! (GIT_EDITOR="$FAKE_EDITOR" git commit)
118 test_expect_success '--no-verify with failing hook' '
120 echo "stuff" >> file &&
121 git add file &&
122 git commit --no-verify -m "stuff"
126 test_expect_success '--no-verify with failing hook (editor)' '
128 echo "more stuff" >> file &&
129 git add file &&
130 echo "more stuff" > FAKE_MSG &&
131 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
135 chmod -x "$HOOK"
136 if test "$(git config --bool core.filemode)" = false; then
137 say "executable bit not honored - skipping tests of non-executable hook"
138 else
140 test_expect_success 'with non-executable hook' '
142 echo "content" >> file &&
143 git add file &&
144 git commit -m "content"
148 test_expect_success 'with non-executable hook (editor)' '
150 echo "content again" >> file &&
151 git add file &&
152 echo "content again" > FAKE_MSG &&
153 GIT_EDITOR="$FAKE_EDITOR" git commit -m "content again"
157 test_expect_success '--no-verify with non-executable hook' '
159 echo "more content" >> file &&
160 git add file &&
161 git commit --no-verify -m "more content"
165 test_expect_success '--no-verify with non-executable hook (editor)' '
167 echo "even more content" >> file &&
168 git add file &&
169 echo "even more content" > FAKE_MSG &&
170 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify
174 fi # non-executable hooks
176 # now a hook that edits the commit message
177 cat > "$HOOK" <<'EOF'
178 #!/bin/sh
179 echo "new message" > "$1"
180 exit 0
182 chmod +x "$HOOK"
184 commit_msg_is () {
185 test "`git log --pretty=format:%s%b -1`" = "$1"
188 test_expect_success 'hook edits commit message' '
190 echo "additional" >> file &&
191 git add file &&
192 git commit -m "additional" &&
193 commit_msg_is "new message"
197 test_expect_success 'hook edits commit message (editor)' '
199 echo "additional content" >> file &&
200 git add file &&
201 echo "additional content" > FAKE_MSG &&
202 GIT_EDITOR="$FAKE_EDITOR" git commit &&
203 commit_msg_is "new message"
207 test_expect_success "hook doesn't edit commit message" '
209 echo "plus" >> file &&
210 git add file &&
211 git commit --no-verify -m "plus" &&
212 commit_msg_is "plus"
216 test_expect_success "hook doesn't edit commit message (editor)" '
218 echo "more plus" >> file &&
219 git add file &&
220 echo "more plus" > FAKE_MSG &&
221 GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify &&
222 commit_msg_is "more plus"
226 test_done