]>
Commit | Line | Data |
---|---|---|
b468f0ce JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='git commit porcelain-ish' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'the basics' ' | |
8 | ||
9 | echo doing partial >"commit is" && | |
10 | mkdir not && | |
11 | echo very much encouraged but we should >not/forbid && | |
12 | git add "commit is" not && | |
13 | echo update added "commit is" file >"commit is" && | |
14 | echo also update another >not/forbid && | |
15 | test_tick && | |
16 | git commit -a -m "initial with -a" && | |
17 | ||
18 | git cat-file blob HEAD:"commit is" >current.1 && | |
19 | git cat-file blob HEAD:not/forbid >current.2 && | |
20 | ||
21 | cmp current.1 "commit is" && | |
22 | cmp current.2 not/forbid | |
23 | ||
24 | ' | |
25 | ||
26 | test_expect_success 'partial' ' | |
27 | ||
28 | echo another >"commit is" && | |
29 | echo another >not/forbid && | |
30 | test_tick && | |
31 | git commit -m "partial commit to handle a file" "commit is" && | |
32 | ||
33 | changed=$(git diff-tree --name-only HEAD^ HEAD) && | |
34 | test "$changed" = "commit is" | |
35 | ||
36 | ' | |
37 | ||
38 | test_expect_success 'partial modification in a subdirecotry' ' | |
39 | ||
40 | test_tick && | |
41 | git commit -m "partial commit to subdirectory" not && | |
42 | ||
43 | changed=$(git diff-tree -r --name-only HEAD^ HEAD) && | |
44 | test "$changed" = "not/forbid" | |
45 | ||
46 | ' | |
47 | ||
48 | test_expect_success 'partial removal' ' | |
49 | ||
50 | git rm not/forbid && | |
51 | git commit -m "partial commit to remove not/forbid" not && | |
52 | ||
53 | changed=$(git diff-tree -r --name-only HEAD^ HEAD) && | |
54 | test "$changed" = "not/forbid" && | |
55 | remain=$(git ls-tree -r --name-only HEAD) && | |
56 | test "$remain" = "commit is" | |
57 | ||
58 | ' | |
59 | ||
60 | test_expect_success 'sign off' ' | |
61 | ||
62 | >positive && | |
63 | git add positive && | |
64 | git commit -s -m "thank you" && | |
65 | actual=$(git cat-file commit HEAD | sed -ne "s/Signed-off-by: //p") && | |
66 | expected=$(git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/") && | |
67 | test "z$actual" = "z$expected" | |
68 | ||
69 | ' | |
70 | ||
71 | test_expect_success 'multiple -m' ' | |
72 | ||
73 | >negative && | |
74 | git add negative && | |
75 | git commit -m "one" -m "two" -m "three" && | |
76 | actual=$(git cat-file commit HEAD | sed -e "1,/^\$/d") && | |
77 | expected=$(echo one; echo; echo two; echo; echo three) && | |
78 | test "z$actual" = "z$expected" | |
79 | ||
80 | ' | |
81 | ||
82 | test_expect_success 'verbose' ' | |
83 | ||
84 | echo minus >negative && | |
85 | git add negative && | |
86 | git status -v | sed -ne "/^diff --git /p" >actual && | |
87 | echo "diff --git a/negative b/negative" >expect && | |
82ebb0b6 | 88 | test_cmp expect actual |
b468f0ce JH |
89 | |
90 | ' | |
91 | ||
5f065737 AR |
92 | test_expect_success 'cleanup commit messages (verbatim,-t)' ' |
93 | ||
94 | echo >>negative && | |
95 | { echo;echo "# text";echo; } >expect && | |
96 | git commit --cleanup=verbatim -t expect -a && | |
97 | git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual && | |
82ebb0b6 | 98 | test_cmp expect actual |
5f065737 AR |
99 | |
100 | ' | |
101 | ||
102 | test_expect_success 'cleanup commit messages (verbatim,-F)' ' | |
103 | ||
104 | echo >>negative && | |
105 | git commit --cleanup=verbatim -F expect -a && | |
106 | git cat-file -p HEAD |sed -e "1,/^\$/d">actual && | |
82ebb0b6 | 107 | test_cmp expect actual |
5f065737 AR |
108 | |
109 | ' | |
110 | ||
111 | test_expect_success 'cleanup commit messages (verbatim,-m)' ' | |
112 | ||
113 | echo >>negative && | |
114 | git commit --cleanup=verbatim -m "$(cat expect)" -a && | |
115 | git cat-file -p HEAD |sed -e "1,/^\$/d">actual && | |
82ebb0b6 | 116 | test_cmp expect actual |
5f065737 AR |
117 | |
118 | ' | |
119 | ||
120 | test_expect_success 'cleanup commit messages (whitespace,-F)' ' | |
121 | ||
122 | echo >>negative && | |
123 | { echo;echo "# text";echo; } >text && | |
124 | echo "# text" >expect && | |
125 | git commit --cleanup=whitespace -F text -a && | |
126 | git cat-file -p HEAD |sed -e "1,/^\$/d">actual && | |
82ebb0b6 | 127 | test_cmp expect actual |
5f065737 AR |
128 | |
129 | ' | |
130 | ||
131 | test_expect_success 'cleanup commit messages (strip,-F)' ' | |
132 | ||
133 | echo >>negative && | |
134 | { echo;echo "# text";echo sample;echo; } >text && | |
135 | echo sample >expect && | |
136 | git commit --cleanup=strip -F text -a && | |
137 | git cat-file -p HEAD |sed -e "1,/^\$/d">actual && | |
82ebb0b6 | 138 | test_cmp expect actual |
5f065737 AR |
139 | |
140 | ' | |
141 | ||
142 | echo "sample | |
143 | ||
144 | # Please enter the commit message for your changes. | |
145 | # (Comment lines starting with '#' will not be included)" >expect | |
146 | ||
147 | test_expect_success 'cleanup commit messages (strip,-F,-e)' ' | |
148 | ||
149 | echo >>negative && | |
150 | { echo;echo sample;echo; } >text && | |
151 | git commit -e -F text -a && | |
152 | head -n 4 .git/COMMIT_EDITMSG >actual && | |
82ebb0b6 | 153 | test_cmp expect actual |
5f065737 AR |
154 | |
155 | ' | |
156 | ||
e83dbe80 SB |
157 | echo "# |
158 | # Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> | |
159 | #" >> expect | |
160 | ||
161 | test_expect_success 'author different from committer' ' | |
162 | ||
163 | echo >>negative && | |
164 | git commit -e -m "sample" | |
165 | head -n 7 .git/COMMIT_EDITMSG >actual && | |
166 | test_cmp expect actual | |
167 | ' | |
168 | ||
d16d5cdf MK |
169 | mv expect expect.tmp |
170 | sed '$d' < expect.tmp > expect | |
171 | rm -f expect.tmp | |
bb1ae3f6 SB |
172 | echo "# Committer: |
173 | #" >> expect | |
bb1ae3f6 SB |
174 | |
175 | test_expect_success 'committer is automatic' ' | |
176 | ||
177 | echo >>negative && | |
7845944c JH |
178 | ( |
179 | unset GIT_COMMITTER_EMAIL | |
180 | unset GIT_COMMITTER_NAME | |
181 | # must fail because there is no change | |
182 | test_must_fail git commit -e -m "sample" | |
183 | ) && | |
bb1ae3f6 SB |
184 | head -n 8 .git/COMMIT_EDITMSG | \ |
185 | sed "s/^# Committer: .*/# Committer:/" >actual && | |
186 | test_cmp expect actual | |
187 | ' | |
188 | ||
ec84bd00 PB |
189 | pwd=`pwd` |
190 | cat >> .git/FAKE_EDITOR << EOF | |
191 | #! /bin/sh | |
192 | echo editor started > "$pwd/.git/result" | |
193 | exit 0 | |
194 | EOF | |
195 | chmod +x .git/FAKE_EDITOR | |
196 | ||
197 | test_expect_success 'do not fire editor in the presence of conflicts' ' | |
198 | ||
a3c91e08 JH |
199 | git clean -f && |
200 | echo f >g && | |
201 | git add g && | |
202 | git commit -m "add g" && | |
203 | git branch second && | |
204 | echo master >g && | |
205 | echo g >h && | |
206 | git add g h && | |
207 | git commit -m "modify g and add h" && | |
208 | git checkout second && | |
209 | echo second >g && | |
210 | git add g && | |
211 | git commit -m second && | |
212 | # Must fail due to conflict | |
213 | test_must_fail git cherry-pick -n master && | |
214 | echo "editor not started" >.git/result && | |
215 | test_must_fail GIT_EDITOR="$(pwd)/.git/FAKE_EDITOR" git commit && | |
216 | test "$(cat .git/result)" = "editor not started" | |
ec84bd00 PB |
217 | ' |
218 | ||
ad5fa3cc | 219 | pwd=`pwd` |
de5825cc JH |
220 | cat >.git/FAKE_EDITOR <<EOF |
221 | #! $SHELL_PATH | |
ad5fa3cc PB |
222 | # kill -TERM command added below. |
223 | EOF | |
224 | ||
225 | test_expect_success 'a SIGTERM should break locks' ' | |
226 | echo >>negative && | |
de5825cc | 227 | "$SHELL_PATH" -c '\'' |
ad5fa3cc PB |
228 | echo kill -TERM $$ >> .git/FAKE_EDITOR |
229 | GIT_EDITOR=.git/FAKE_EDITOR exec git commit -a'\'' && exit 1 # should fail | |
230 | ! test -f .git/index.lock | |
231 | ' | |
232 | ||
67bfc030 JH |
233 | rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG |
234 | git reset -q --hard | |
235 | ||
236 | test_expect_success 'Hand committing of a redundant merge removes dups' ' | |
237 | ||
238 | git rev-parse second master >expect && | |
239 | test_must_fail git merge second master && | |
240 | git checkout master g && | |
241 | EDITOR=: git commit -a && | |
242 | git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual && | |
243 | test_cmp expect actual | |
244 | ||
245 | ' | |
246 | ||
b468f0ce | 247 | test_done |