]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7505-prepare-commit-msg-hook.sh
Don't use the 'export NAME=value' in the test scripts.
[thirdparty/git.git] / t / t7505-prepare-commit-msg-hook.sh
1 #!/bin/sh
2
3 test_description='prepare-commit-msg hook'
4
5 . ./test-lib.sh
6
7 test_expect_success 'with no hook' '
8
9 echo "foo" > file &&
10 git add file &&
11 git commit -m "first"
12
13 '
14
15 # set up fake editor for interactive editing
16 cat > fake-editor <<'EOF'
17 #!/bin/sh
18 exit 0
19 EOF
20 chmod +x fake-editor
21 FAKE_EDITOR="$(pwd)/fake-editor"
22 export FAKE_EDITOR
23
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"
27 mkdir -p "$HOOKDIR"
28 echo "#!$SHELL_PATH" > "$HOOK"
29 cat >> "$HOOK" <<'EOF'
30
31 if test "$2" = commit; then
32 source=$(git-rev-parse "$3")
33 else
34 source=${2-default}
35 fi
36 if test "$GIT_EDITOR" = :; then
37 sed -e "1s/.*/$source (no editor)/" "$1" > msg.tmp
38 else
39 sed -e "1s/.*/$source/" "$1" > msg.tmp
40 fi
41 mv msg.tmp "$1"
42 exit 0
43 EOF
44 chmod +x "$HOOK"
45
46 echo dummy template > "$(git rev-parse --git-dir)/template"
47
48 test_expect_success 'with hook (-m)' '
49
50 echo "more" >> file &&
51 git add file &&
52 git commit -m "more" &&
53 test "`git log -1 --pretty=format:%s`" = "message (no editor)"
54
55 '
56
57 test_expect_success 'with hook (-m editor)' '
58
59 echo "more" >> file &&
60 git add file &&
61 GIT_EDITOR="$FAKE_EDITOR" git commit -e -m "more more" &&
62 test "`git log -1 --pretty=format:%s`" = message
63
64 '
65
66 test_expect_success 'with hook (-t)' '
67
68 echo "more" >> file &&
69 git add file &&
70 git commit -t "$(git rev-parse --git-dir)/template" &&
71 test "`git log -1 --pretty=format:%s`" = template
72
73 '
74
75 test_expect_success 'with hook (-F)' '
76
77 echo "more" >> file &&
78 git add file &&
79 (echo more | git commit -F -) &&
80 test "`git log -1 --pretty=format:%s`" = "message (no editor)"
81
82 '
83
84 test_expect_success 'with hook (-F editor)' '
85
86 echo "more" >> file &&
87 git add file &&
88 (echo more more | GIT_EDITOR="$FAKE_EDITOR" git commit -e -F -) &&
89 test "`git log -1 --pretty=format:%s`" = message
90
91 '
92
93 test_expect_success 'with hook (-C)' '
94
95 head=`git rev-parse HEAD` &&
96 echo "more" >> file &&
97 git add file &&
98 git commit -C $head &&
99 test "`git log -1 --pretty=format:%s`" = "$head (no editor)"
100
101 '
102
103 test_expect_success 'with hook (editor)' '
104
105 echo "more more" >> file &&
106 git add file &&
107 GIT_EDITOR="$FAKE_EDITOR" git commit &&
108 test "`git log -1 --pretty=format:%s`" = default
109
110 '
111
112 test_expect_success 'with hook (--amend)' '
113
114 head=`git rev-parse HEAD` &&
115 echo "more" >> file &&
116 git add file &&
117 GIT_EDITOR="$FAKE_EDITOR" git commit --amend &&
118 test "`git log -1 --pretty=format:%s`" = "$head"
119
120 '
121
122 test_expect_success 'with hook (-c)' '
123
124 head=`git rev-parse HEAD` &&
125 echo "more" >> file &&
126 git add file &&
127 GIT_EDITOR="$FAKE_EDITOR" git commit -c $head &&
128 test "`git log -1 --pretty=format:%s`" = "$head"
129
130 '
131
132 cat > "$HOOK" <<'EOF'
133 #!/bin/sh
134 exit 1
135 EOF
136
137 test_expect_success 'with failing hook' '
138
139 head=`git rev-parse HEAD` &&
140 echo "more" >> file &&
141 git add file &&
142 ! GIT_EDITOR="$FAKE_EDITOR" git commit -c $head
143
144 '
145
146 test_expect_success 'with failing hook (--no-verify)' '
147
148 head=`git rev-parse HEAD` &&
149 echo "more" >> file &&
150 git add file &&
151 ! GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify -c $head
152
153 '
154
155
156 test_done