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"
30 if test "$2" = commit; then
31 source=$(git-rev-parse "$3")
35 if test "$GIT_EDITOR" = :; then
36 sed -e "1s/.*/$source (no editor)/" "$1" > msg.tmp
38 sed -e "1s/.*/$source/" "$1" > msg.tmp
45 echo dummy template
> "$(git rev-parse --git-dir)/template"
47 test_expect_success
'with hook (-m)' '
49 echo "more" >> file &&
51 git commit -m "more" &&
52 test "`git log -1 --pretty=format:%s`" = "message (no editor)"
56 test_expect_success
'with hook (-m editor)' '
58 echo "more" >> file &&
60 GIT_EDITOR="$FAKE_EDITOR" git commit -e -m "more more" &&
61 test "`git log -1 --pretty=format:%s`" = message
65 test_expect_success
'with hook (-t)' '
67 echo "more" >> file &&
69 git commit -t "$(git rev-parse --git-dir)/template" &&
70 test "`git log -1 --pretty=format:%s`" = template
74 test_expect_success
'with hook (-F)' '
76 echo "more" >> file &&
78 (echo more | git commit -F -) &&
79 test "`git log -1 --pretty=format:%s`" = "message (no editor)"
83 test_expect_success
'with hook (-F editor)' '
85 echo "more" >> file &&
87 (echo more more | GIT_EDITOR="$FAKE_EDITOR" git commit -e -F -) &&
88 test "`git log -1 --pretty=format:%s`" = message
92 test_expect_success
'with hook (-C)' '
94 head=`git rev-parse HEAD` &&
95 echo "more" >> file &&
97 git commit -C $head &&
98 test "`git log -1 --pretty=format:%s`" = "$head (no editor)"
102 test_expect_success
'with hook (editor)' '
104 echo "more more" >> file &&
106 GIT_EDITOR="$FAKE_EDITOR" git commit &&
107 test "`git log -1 --pretty=format:%s`" = default
111 test_expect_success
'with hook (--amend)' '
113 head=`git rev-parse HEAD` &&
114 echo "more" >> file &&
116 GIT_EDITOR="$FAKE_EDITOR" git commit --amend &&
117 test "`git log -1 --pretty=format:%s`" = "$head"
121 test_expect_success
'with hook (-c)' '
123 head=`git rev-parse HEAD` &&
124 echo "more" >> file &&
126 GIT_EDITOR="$FAKE_EDITOR" git commit -c $head &&
127 test "`git log -1 --pretty=format:%s`" = "$head"
131 cat > "$HOOK" <<'EOF'
136 test_expect_success
'with failing hook' '
138 head=`git rev-parse HEAD` &&
139 echo "more" >> file &&
141 ! GIT_EDITOR="$FAKE_EDITOR" git commit -c $head
145 test_expect_success
'with failing hook (--no-verify)' '
147 head=`git rev-parse HEAD` &&
148 echo "more" >> file &&
150 ! GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify -c $head