]>
Commit | Line | Data |
---|---|---|
12ace0b2 KH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com> | |
4 | # | |
5 | ||
6 | # FIXME: Test the various index usages, -i and -o, test reflog, | |
264474f2 | 7 | # signoff |
12ace0b2 KH |
8 | |
9 | test_description='git-commit' | |
10 | . ./test-lib.sh | |
11 | ||
12 | test_tick | |
13 | ||
14 | test_expect_success \ | |
15 | "initial status" \ | |
16 | "echo 'bongo bongo' >file && | |
17 | git-add file && \ | |
18 | git-status | grep 'Initial commit'" | |
19 | ||
20 | test_expect_failure \ | |
21 | "fail initial amend" \ | |
22 | "git-commit --amend" | |
23 | ||
24 | test_expect_success \ | |
25 | "initial commit" \ | |
26 | "git-commit -m initial" | |
27 | ||
28 | test_expect_failure \ | |
29 | "invalid options 1" \ | |
6d4bbebd | 30 | "git-commit -m foo -m bar -F file" |
12ace0b2 KH |
31 | |
32 | test_expect_failure \ | |
33 | "invalid options 2" \ | |
34 | "git-commit -C HEAD -m illegal" | |
35 | ||
9d87442f BS |
36 | test_expect_failure \ |
37 | "using paths with -a" \ | |
38 | "echo King of the bongo >file && | |
39 | git-commit -m foo -a file" | |
40 | ||
41 | test_expect_failure \ | |
42 | "using paths with --interactive" \ | |
43 | "echo bong-o-bong >file && | |
44 | echo 7 | git-commit -m foo --interactive file" | |
45 | ||
12ace0b2 KH |
46 | test_expect_failure \ |
47 | "using invalid commit with -C" \ | |
48 | "git-commit -C bogus" | |
49 | ||
50 | test_expect_failure \ | |
51 | "testing nothing to commit" \ | |
52 | "git-commit -m initial" | |
53 | ||
54 | test_expect_success \ | |
55 | "next commit" \ | |
56 | "echo 'bongo bongo bongo' >file \ | |
57 | git-commit -m next -a" | |
58 | ||
59 | test_expect_failure \ | |
60 | "commit message from non-existing file" \ | |
61 | "echo 'more bongo: bongo bongo bongo bongo' >file && \ | |
62 | git-commit -F gah -a" | |
63 | ||
64 | # Empty except stray tabs and spaces on a few lines. | |
65 | sed -e 's/@$//' >msg <<EOF | |
66 | @ | |
67 | ||
68 | @ | |
69 | Signed-off-by: hula | |
70 | EOF | |
71 | test_expect_failure \ | |
72 | "empty commit message" \ | |
73 | "git-commit -F msg -a" | |
74 | ||
75 | test_expect_success \ | |
76 | "commit message from file" \ | |
77 | "echo 'this is the commit message, coming from a file' >msg && \ | |
78 | git-commit -F msg -a" | |
79 | ||
80 | cat >editor <<\EOF | |
81 | #!/bin/sh | |
41ec097a JS |
82 | sed -e "s/a file/an amend commit/g" < $1 > $1- |
83 | mv $1- $1 | |
12ace0b2 KH |
84 | EOF |
85 | chmod 755 editor | |
86 | ||
87 | test_expect_success \ | |
88 | "amend commit" \ | |
89 | "VISUAL=./editor git-commit --amend" | |
90 | ||
91 | test_expect_failure \ | |
6d4bbebd | 92 | "passing -m and -F" \ |
12ace0b2 | 93 | "echo 'enough with the bongos' >file && \ |
6d4bbebd | 94 | git-commit -F msg -m amending ." |
12ace0b2 KH |
95 | |
96 | test_expect_success \ | |
97 | "using message from other commit" \ | |
98 | "git-commit -C HEAD^ ." | |
99 | ||
100 | cat >editor <<\EOF | |
101 | #!/bin/sh | |
41ec097a JS |
102 | sed -e "s/amend/older/g" < $1 > $1- |
103 | mv $1- $1 | |
12ace0b2 KH |
104 | EOF |
105 | chmod 755 editor | |
106 | ||
107 | test_expect_success \ | |
108 | "editing message from other commit" \ | |
109 | "echo 'hula hula' >file && \ | |
110 | VISUAL=./editor git-commit -c HEAD^ -a" | |
111 | ||
112 | test_expect_success \ | |
113 | "message from stdin" \ | |
114 | "echo 'silly new contents' >file && \ | |
115 | echo commit message from stdin | git-commit -F - -a" | |
116 | ||
117 | test_expect_success \ | |
118 | "overriding author from command line" \ | |
119 | "echo 'gak' >file && \ | |
120 | git-commit -m 'author' --author 'Rubber Duck <rduck@convoy.org>' -a" | |
121 | ||
122 | test_expect_success \ | |
123 | "interactive add" \ | |
124 | "echo 7 | git-commit --interactive | grep 'What now'" | |
125 | ||
126 | test_expect_success \ | |
127 | "showing committed revisions" \ | |
128 | "git-rev-list HEAD >current" | |
129 | ||
130 | # We could just check the head sha1, but checking each commit makes it | |
131 | # easier to isolate bugs. | |
132 | ||
133 | cat >expected <<\EOF | |
134 | 72c0dc9855b0c9dadcbfd5a31cab072e0cb774ca | |
135 | 9b88fc14ce6b32e3d9ee021531a54f18a5cf38a2 | |
136 | 3536bbb352c3a1ef9a420f5b4242d48578b92aa7 | |
137 | d381ac431806e53f3dd7ac2f1ae0534f36d738b9 | |
138 | 4fd44095ad6334f3ef72e4c5ec8ddf108174b54a | |
139 | 402702b49136e7587daa9280e91e4bb7cb2179f7 | |
140 | EOF | |
141 | ||
142 | test_expect_success \ | |
143 | 'validate git-rev-list output.' \ | |
144 | 'diff current expected' | |
145 | ||
db33af0a | 146 | test_expect_success 'partial commit that involves removal (1)' ' |
80bffaf7 JH |
147 | |
148 | git rm --cached file && | |
149 | mv file elif && | |
150 | git add elif && | |
151 | git commit -m "Partial: add elif" elif && | |
152 | git diff-tree --name-status HEAD^ HEAD >current && | |
153 | echo "A elif" >expected && | |
154 | diff expected current | |
155 | ||
156 | ' | |
157 | ||
db33af0a | 158 | test_expect_success 'partial commit that involves removal (2)' ' |
80bffaf7 JH |
159 | |
160 | git commit -m "Partial: remove file" file && | |
161 | git diff-tree --name-status HEAD^ HEAD >current && | |
162 | echo "D file" >expected && | |
163 | diff expected current | |
164 | ||
165 | ' | |
166 | ||
db33af0a JH |
167 | test_expect_success 'partial commit that involves removal (3)' ' |
168 | ||
169 | git rm --cached elif && | |
170 | echo elif >elif && | |
171 | git commit -m "Partial: modify elif" elif && | |
172 | git diff-tree --name-status HEAD^ HEAD >current && | |
173 | echo "M elif" >expected && | |
174 | diff expected current | |
175 | ||
176 | ' | |
177 | ||
5aa5cd46 JH |
178 | author="The Real Author <someguy@his.email.org>" |
179 | test_expect_success 'amend commit to fix author' ' | |
180 | ||
181 | oldtick=$GIT_AUTHOR_DATE && | |
182 | test_tick && | |
183 | git reset --hard && | |
184 | git cat-file -p HEAD | | |
185 | sed -e "s/author.*/author $author $oldtick/" \ | |
186 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
187 | expected && | |
188 | git commit --amend --author="$author" && | |
189 | git cat-file -p HEAD > current && | |
190 | diff expected current | |
191 | ||
192 | ' | |
193 | ||
194 | test_expect_success 'sign off (1)' ' | |
195 | ||
196 | echo 1 >positive && | |
197 | git add positive && | |
198 | git commit -s -m "thank you" && | |
199 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
200 | ( | |
201 | echo thank you | |
202 | echo | |
203 | git var GIT_COMMITTER_IDENT | | |
204 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
205 | ) >expected && | |
206 | diff -u expected actual | |
207 | ||
208 | ' | |
209 | ||
210 | test_expect_success 'sign off (2)' ' | |
211 | ||
212 | echo 2 >positive && | |
213 | git add positive && | |
214 | existing="Signed-off-by: Watch This <watchthis@example.com>" && | |
215 | git commit -s -m "thank you | |
216 | ||
217 | $existing" && | |
218 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
219 | ( | |
220 | echo thank you | |
221 | echo | |
222 | echo $existing | |
223 | git var GIT_COMMITTER_IDENT | | |
224 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
225 | ) >expected && | |
226 | diff -u expected actual | |
227 | ||
228 | ' | |
229 | ||
230 | test_expect_success 'multiple -m' ' | |
231 | ||
232 | >negative && | |
233 | git add negative && | |
234 | git commit -m "one" -m "two" -m "three" && | |
235 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
236 | ( | |
237 | echo one | |
238 | echo | |
239 | echo two | |
240 | echo | |
241 | echo three | |
242 | ) >expected && | |
243 | diff -u expected actual | |
244 | ||
245 | ' | |
246 | ||
d63c2fd1 KH |
247 | author="The Real Author <someguy@his.email.org>" |
248 | test_expect_success 'amend commit to fix author' ' | |
249 | ||
250 | oldtick=$GIT_AUTHOR_DATE && | |
251 | test_tick && | |
252 | git reset --hard && | |
253 | git cat-file -p HEAD | | |
254 | sed -e "s/author.*/author $author $oldtick/" \ | |
255 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
256 | expected && | |
257 | git commit --amend --author="$author" && | |
258 | git cat-file -p HEAD > current && | |
259 | diff expected current | |
260 | ||
261 | ' | |
1200993a KH |
262 | |
263 | test_expect_success 'git commit <file> with dirty index' ' | |
264 | echo tacocat > elif && | |
265 | echo tehlulz > chz && | |
266 | git add chz && | |
267 | git commit elif -m "tacocat is a palindrome" && | |
268 | git show --stat | grep elif && | |
269 | git diff --cached | grep chz | |
270 | ' | |
271 | ||
13aba1e5 JS |
272 | test_expect_success 'same tree (single parent)' ' |
273 | ||
31cbb5d9 JH |
274 | git reset --hard |
275 | ||
13aba1e5 JS |
276 | if git commit -m empty |
277 | then | |
278 | echo oops -- should have complained | |
279 | false | |
280 | else | |
281 | : happy | |
282 | fi | |
283 | ||
284 | ' | |
285 | ||
36863af1 JH |
286 | test_expect_success 'same tree (single parent) --allow-empty' ' |
287 | ||
288 | git commit --allow-empty -m "forced empty" && | |
289 | git cat-file commit HEAD | grep forced | |
290 | ||
291 | ' | |
292 | ||
13aba1e5 JS |
293 | test_expect_success 'same tree (merge and amend merge)' ' |
294 | ||
295 | git checkout -b side HEAD^ && | |
296 | echo zero >zero && | |
297 | git add zero && | |
298 | git commit -m "add zero" && | |
299 | git checkout master && | |
300 | ||
301 | git merge -s ours side -m "empty ok" && | |
302 | git diff HEAD^ HEAD >actual && | |
303 | : >expected && | |
304 | diff -u expected actual && | |
305 | ||
306 | git commit --amend -m "empty really ok" && | |
307 | git diff HEAD^ HEAD >actual && | |
308 | : >expected && | |
309 | diff -u expected actual | |
310 | ||
311 | ' | |
312 | ||
1eb1e9ee JH |
313 | test_expect_success 'amend using the message from another commit' ' |
314 | ||
315 | git reset --hard && | |
316 | test_tick && | |
317 | git commit --allow-empty -m "old commit" && | |
318 | old=$(git rev-parse --verify HEAD) && | |
319 | test_tick && | |
320 | git commit --allow-empty -m "new commit" && | |
321 | new=$(git rev-parse --verify HEAD) && | |
322 | test_tick && | |
323 | git commit --allow-empty --amend -C "$old" && | |
324 | git show --pretty="format:%ad %s" "$old" >expected && | |
325 | git show --pretty="format:%ad %s" HEAD >actual && | |
326 | diff -u expected actual | |
327 | ||
328 | ' | |
329 | ||
12ace0b2 | 330 | test_done |