3 test_description
='prepare-commit-msg hook'
7 test_expect_success
'with no hook' '
15 # set up fake editor for interactive editing
16 cat > fake-editor
<<'EOF'
21 FAKE_EDITOR
="$(pwd)/fake-editor"
24 # now install hook that always succeeds and adds a message
25 HOOKDIR
="$(git rev-parse --git-dir)/hooks"
26 HOOK
="$HOOKDIR/prepare-commit-msg"
28 echo "#!$SHELL_PATH" > "$HOOK"
29 cat >> "$HOOK" <<'EOF'
31 if test "$2" = commit; then
32 source=$(git-rev-parse "$3")
36 if test "$GIT_EDITOR" = :; then
37 sed -e "1s/.*/$source (no editor)/" "$1" > msg.tmp
39 sed -e "1s/.*/$source/" "$1" > msg.tmp
46 echo dummy template
> "$(git rev-parse --git-dir)/template"
48 test_expect_success
'with hook (-m)' '
50 echo "more" >> file &&
52 git commit -m "more" &&
53 test "`git log -1 --pretty=format:%s`" = "message (no editor)"
57 test_expect_success
'with hook (-m editor)' '
59 echo "more" >> file &&
61 GIT_EDITOR="$FAKE_EDITOR" git commit -e -m "more more" &&
62 test "`git log -1 --pretty=format:%s`" = message
66 test_expect_success
'with hook (-t)' '
68 echo "more" >> file &&
70 git commit -t "$(git rev-parse --git-dir)/template" &&
71 test "`git log -1 --pretty=format:%s`" = template
75 test_expect_success
'with hook (-F)' '
77 echo "more" >> file &&
79 (echo more | git commit -F -) &&
80 test "`git log -1 --pretty=format:%s`" = "message (no editor)"
84 test_expect_success
'with hook (-F editor)' '
86 echo "more" >> file &&
88 (echo more more | GIT_EDITOR="$FAKE_EDITOR" git commit -e -F -) &&
89 test "`git log -1 --pretty=format:%s`" = message
93 test_expect_success
'with hook (-C)' '
95 head=`git rev-parse HEAD` &&
96 echo "more" >> file &&
98 git commit -C $head &&
99 test "`git log -1 --pretty=format:%s`" = "$head (no editor)"
103 test_expect_success
'with hook (editor)' '
105 echo "more more" >> file &&
107 GIT_EDITOR="$FAKE_EDITOR" git commit &&
108 test "`git log -1 --pretty=format:%s`" = default
112 test_expect_success
'with hook (--amend)' '
114 head=`git rev-parse HEAD` &&
115 echo "more" >> file &&
117 GIT_EDITOR="$FAKE_EDITOR" git commit --amend &&
118 test "`git log -1 --pretty=format:%s`" = "$head"
122 test_expect_success
'with hook (-c)' '
124 head=`git rev-parse HEAD` &&
125 echo "more" >> file &&
127 GIT_EDITOR="$FAKE_EDITOR" git commit -c $head &&
128 test "`git log -1 --pretty=format:%s`" = "$head"
132 cat > "$HOOK" <<'EOF'
137 test_expect_success
'with failing hook' '
139 head=`git rev-parse HEAD` &&
140 echo "more" >> file &&
142 ! GIT_EDITOR="$FAKE_EDITOR" git commit -c $head
146 test_expect_success
'with failing hook (--no-verify)' '
148 head=`git rev-parse HEAD` &&
149 echo "more" >> file &&
151 ! GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify -c $head