##// END OF EJS Templates
commitextras: make sure keys are not empty...
Pulkit Goyal -
r33607:80635169 stable
parent child Browse files
Show More
@@ -1,73 +1,76 b''
1 1 # commitextras.py
2 2 #
3 3 # Copyright 2013 Facebook, Inc.
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 '''adds a new flag extras to commit (ADVANCED)'''
9 9
10 10 from __future__ import absolute_import
11 11
12 12 import re
13 13
14 14 from mercurial.i18n import _
15 15 from mercurial import (
16 16 commands,
17 17 error,
18 18 extensions,
19 19 registrar,
20 20 )
21 21
22 22 cmdtable = {}
23 23 command = registrar.command(cmdtable)
24 24 testedwith = 'ships-with-hg-core'
25 25
26 26 usedinternally = {
27 27 'amend_source',
28 28 'branch',
29 29 'close',
30 30 'histedit_source',
31 31 'topic',
32 32 'rebase_source',
33 33 'intermediate-source',
34 34 '__touch-noise__',
35 35 'source',
36 36 'transplant_source',
37 37 }
38 38
39 39 def extsetup(ui):
40 40 entry = extensions.wrapcommand(commands.table, 'commit', _commit)
41 41 options = entry[1]
42 42 options.append(('', 'extra', [],
43 43 _('set a changeset\'s extra values'), _("KEY=VALUE")))
44 44
45 45 def _commit(orig, ui, repo, *pats, **opts):
46 46 origcommit = repo.commit
47 47 try:
48 48 def _wrappedcommit(*innerpats, **inneropts):
49 49 extras = opts.get('extra')
50 50 if extras:
51 51 for raw in extras:
52 52 if '=' not in raw:
53 53 msg = _("unable to parse '%s', should follow "
54 54 "KEY=VALUE format")
55 55 raise error.Abort(msg % raw)
56 56 k, v = raw.split('=', 1)
57 if not k:
58 msg = _("unable to parse '%s', keys can't be empty")
59 raise error.Abort(msg % raw)
57 60 if re.search('[^\w-]', k):
58 61 msg = _("keys can only contain ascii letters, digits,"
59 62 " '_' and '-'")
60 63 raise error.Abort(msg)
61 64 if k in usedinternally:
62 65 msg = _("key '%s' is used internally, can't be set "
63 66 "manually")
64 67 raise error.Abort(msg % k)
65 68 inneropts['extra'][k] = v
66 69 return origcommit(*innerpats, **inneropts)
67 70
68 71 # This __dict__ logic is needed because the normal
69 72 # extension.wrapfunction doesn't seem to work.
70 73 repo.__dict__['commit'] = _wrappedcommit
71 74 return orig(ui, repo, *pats, **opts)
72 75 finally:
73 76 del repo.__dict__['commit']
@@ -1,813 +1,816 b''
1 1 commit date test
2 2
3 3 $ hg init test
4 4 $ cd test
5 5 $ echo foo > foo
6 6 $ hg add foo
7 7 $ cat > $TESTTMP/checkeditform.sh <<EOF
8 8 > env | grep HGEDITFORM
9 9 > true
10 10 > EOF
11 11 $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg commit -m ""
12 12 HGEDITFORM=commit.normal.normal
13 13 abort: empty commit message
14 14 [255]
15 15 $ hg commit -d '0 0' -m commit-1
16 16 $ echo foo >> foo
17 17 $ hg commit -d '1 4444444' -m commit-3
18 18 hg: parse error: impossible time zone offset: 4444444
19 19 [255]
20 20 $ hg commit -d '1 15.1' -m commit-4
21 21 hg: parse error: invalid date: '1\t15.1'
22 22 [255]
23 23 $ hg commit -d 'foo bar' -m commit-5
24 24 hg: parse error: invalid date: 'foo bar'
25 25 [255]
26 26 $ hg commit -d ' 1 4444' -m commit-6
27 27 $ hg commit -d '111111111111 0' -m commit-7
28 28 hg: parse error: date exceeds 32 bits: 111111111111
29 29 [255]
30 30 $ hg commit -d '-111111111111 0' -m commit-7
31 31 hg: parse error: date exceeds 32 bits: -111111111111
32 32 [255]
33 33 $ echo foo >> foo
34 34 $ hg commit -d '1901-12-13 20:45:52 +0000' -m commit-7-2
35 35 $ echo foo >> foo
36 36 $ hg commit -d '-2147483648 0' -m commit-7-3
37 37 $ hg log -T '{rev} {date|isodatesec}\n' -l2
38 38 3 1901-12-13 20:45:52 +0000
39 39 2 1901-12-13 20:45:52 +0000
40 40 $ hg commit -d '1901-12-13 20:45:51 +0000' -m commit-7
41 41 hg: parse error: date exceeds 32 bits: -2147483649
42 42 [255]
43 43 $ hg commit -d '-2147483649 0' -m commit-7
44 44 hg: parse error: date exceeds 32 bits: -2147483649
45 45 [255]
46 46
47 47 commit added file that has been deleted
48 48
49 49 $ echo bar > bar
50 50 $ hg add bar
51 51 $ rm bar
52 52 $ hg commit -m commit-8
53 53 nothing changed (1 missing files, see 'hg status')
54 54 [1]
55 55 $ hg commit -m commit-8-2 bar
56 56 abort: bar: file not found!
57 57 [255]
58 58
59 59 $ hg -q revert -a --no-backup
60 60
61 61 $ mkdir dir
62 62 $ echo boo > dir/file
63 63 $ hg add
64 64 adding dir/file (glob)
65 65 $ hg -v commit -m commit-9 dir
66 66 committing files:
67 67 dir/file
68 68 committing manifest
69 69 committing changelog
70 70 committed changeset 4:1957363f1ced
71 71
72 72 $ echo > dir.file
73 73 $ hg add
74 74 adding dir.file
75 75 $ hg commit -m commit-10 dir dir.file
76 76 abort: dir: no match under directory!
77 77 [255]
78 78
79 79 $ echo >> dir/file
80 80 $ mkdir bleh
81 81 $ mkdir dir2
82 82 $ cd bleh
83 83 $ hg commit -m commit-11 .
84 84 abort: bleh: no match under directory!
85 85 [255]
86 86 $ hg commit -m commit-12 ../dir ../dir2
87 87 abort: dir2: no match under directory!
88 88 [255]
89 89 $ hg -v commit -m commit-13 ../dir
90 90 committing files:
91 91 dir/file
92 92 committing manifest
93 93 committing changelog
94 94 committed changeset 5:a31d8f87544a
95 95 $ cd ..
96 96
97 97 $ hg commit -m commit-14 does-not-exist
98 98 abort: does-not-exist: * (glob)
99 99 [255]
100 100
101 101 #if symlink
102 102 $ ln -s foo baz
103 103 $ hg commit -m commit-15 baz
104 104 abort: baz: file not tracked!
105 105 [255]
106 106 $ rm baz
107 107 #endif
108 108
109 109 $ touch quux
110 110 $ hg commit -m commit-16 quux
111 111 abort: quux: file not tracked!
112 112 [255]
113 113 $ echo >> dir/file
114 114 $ hg -v commit -m commit-17 dir/file
115 115 committing files:
116 116 dir/file
117 117 committing manifest
118 118 committing changelog
119 119 committed changeset 6:32d054c9d085
120 120
121 121 An empty date was interpreted as epoch origin
122 122
123 123 $ echo foo >> foo
124 124 $ hg commit -d '' -m commit-no-date --config devel.default-date=
125 125 $ hg tip --template '{date|isodate}\n' | grep '1970'
126 126 [1]
127 127
128 128 Using the advanced --extra flag
129 129
130 130 $ echo "[extensions]" >> $HGRCPATH
131 131 $ echo "commitextras=" >> $HGRCPATH
132 132 $ hg status
133 133 ? quux
134 134 $ hg add quux
135 135 $ hg commit -m "adding internal used extras" --extra amend_source=hash
136 136 abort: key 'amend_source' is used internally, can't be set manually
137 137 [255]
138 138 $ hg commit -m "special chars in extra" --extra id@phab=214
139 139 abort: keys can only contain ascii letters, digits, '_' and '-'
140 140 [255]
141 $ hg commit -m "empty key" --extra =value
142 abort: unable to parse '=value', keys can't be empty
143 [255]
141 144 $ hg commit -m "adding extras" --extra sourcehash=foo --extra oldhash=bar
142 145 $ hg log -r . -T '{extras % "{extra}\n"}'
143 146 branch=default
144 147 oldhash=bar
145 148 sourcehash=foo
146 149
147 150 Make sure we do not obscure unknown requires file entries (issue2649)
148 151
149 152 $ echo foo >> foo
150 153 $ echo fake >> .hg/requires
151 154 $ hg commit -m bla
152 155 abort: repository requires features unknown to this Mercurial: fake!
153 156 (see https://mercurial-scm.org/wiki/MissingRequirement for more information)
154 157 [255]
155 158
156 159 $ cd ..
157 160
158 161
159 162 partial subdir commit test
160 163
161 164 $ hg init test2
162 165 $ cd test2
163 166 $ mkdir foo
164 167 $ echo foo > foo/foo
165 168 $ mkdir bar
166 169 $ echo bar > bar/bar
167 170 $ hg add
168 171 adding bar/bar (glob)
169 172 adding foo/foo (glob)
170 173 $ HGEDITOR=cat hg ci -e -m commit-subdir-1 foo
171 174 commit-subdir-1
172 175
173 176
174 177 HG: Enter commit message. Lines beginning with 'HG:' are removed.
175 178 HG: Leave message empty to abort commit.
176 179 HG: --
177 180 HG: user: test
178 181 HG: branch 'default'
179 182 HG: added foo/foo
180 183
181 184
182 185 $ hg ci -m commit-subdir-2 bar
183 186
184 187 subdir log 1
185 188
186 189 $ hg log -v foo
187 190 changeset: 0:f97e73a25882
188 191 user: test
189 192 date: Thu Jan 01 00:00:00 1970 +0000
190 193 files: foo/foo
191 194 description:
192 195 commit-subdir-1
193 196
194 197
195 198
196 199 subdir log 2
197 200
198 201 $ hg log -v bar
199 202 changeset: 1:aa809156d50d
200 203 tag: tip
201 204 user: test
202 205 date: Thu Jan 01 00:00:00 1970 +0000
203 206 files: bar/bar
204 207 description:
205 208 commit-subdir-2
206 209
207 210
208 211
209 212 full log
210 213
211 214 $ hg log -v
212 215 changeset: 1:aa809156d50d
213 216 tag: tip
214 217 user: test
215 218 date: Thu Jan 01 00:00:00 1970 +0000
216 219 files: bar/bar
217 220 description:
218 221 commit-subdir-2
219 222
220 223
221 224 changeset: 0:f97e73a25882
222 225 user: test
223 226 date: Thu Jan 01 00:00:00 1970 +0000
224 227 files: foo/foo
225 228 description:
226 229 commit-subdir-1
227 230
228 231
229 232 $ cd ..
230 233
231 234
232 235 dot and subdir commit test
233 236
234 237 $ hg init test3
235 238 $ echo commit-foo-subdir > commit-log-test
236 239 $ cd test3
237 240 $ mkdir foo
238 241 $ echo foo content > foo/plain-file
239 242 $ hg add foo/plain-file
240 243 $ HGEDITOR=cat hg ci --edit -l ../commit-log-test foo
241 244 commit-foo-subdir
242 245
243 246
244 247 HG: Enter commit message. Lines beginning with 'HG:' are removed.
245 248 HG: Leave message empty to abort commit.
246 249 HG: --
247 250 HG: user: test
248 251 HG: branch 'default'
249 252 HG: added foo/plain-file
250 253
251 254
252 255 $ echo modified foo content > foo/plain-file
253 256 $ hg ci -m commit-foo-dot .
254 257
255 258 full log
256 259
257 260 $ hg log -v
258 261 changeset: 1:95b38e3a5b2e
259 262 tag: tip
260 263 user: test
261 264 date: Thu Jan 01 00:00:00 1970 +0000
262 265 files: foo/plain-file
263 266 description:
264 267 commit-foo-dot
265 268
266 269
267 270 changeset: 0:65d4e9386227
268 271 user: test
269 272 date: Thu Jan 01 00:00:00 1970 +0000
270 273 files: foo/plain-file
271 274 description:
272 275 commit-foo-subdir
273 276
274 277
275 278
276 279 subdir log
277 280
278 281 $ cd foo
279 282 $ hg log .
280 283 changeset: 1:95b38e3a5b2e
281 284 tag: tip
282 285 user: test
283 286 date: Thu Jan 01 00:00:00 1970 +0000
284 287 summary: commit-foo-dot
285 288
286 289 changeset: 0:65d4e9386227
287 290 user: test
288 291 date: Thu Jan 01 00:00:00 1970 +0000
289 292 summary: commit-foo-subdir
290 293
291 294 $ cd ..
292 295 $ cd ..
293 296
294 297 Issue1049: Hg permits partial commit of merge without warning
295 298
296 299 $ hg init issue1049
297 300 $ cd issue1049
298 301 $ echo a > a
299 302 $ hg ci -Ama
300 303 adding a
301 304 $ echo a >> a
302 305 $ hg ci -mb
303 306 $ hg up 0
304 307 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
305 308 $ echo b >> a
306 309 $ hg ci -mc
307 310 created new head
308 311 $ HGMERGE=true hg merge
309 312 merging a
310 313 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
311 314 (branch merge, don't forget to commit)
312 315
313 316 should fail because we are specifying a file name
314 317
315 318 $ hg ci -mmerge a
316 319 abort: cannot partially commit a merge (do not specify files or patterns)
317 320 [255]
318 321
319 322 should fail because we are specifying a pattern
320 323
321 324 $ hg ci -mmerge -I a
322 325 abort: cannot partially commit a merge (do not specify files or patterns)
323 326 [255]
324 327
325 328 should succeed
326 329
327 330 $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg ci -mmerge --edit
328 331 HGEDITFORM=commit.normal.merge
329 332 $ cd ..
330 333
331 334
332 335 test commit message content
333 336
334 337 $ hg init commitmsg
335 338 $ cd commitmsg
336 339 $ echo changed > changed
337 340 $ echo removed > removed
338 341 $ hg book activebookmark
339 342 $ hg ci -qAm init
340 343
341 344 $ hg rm removed
342 345 $ echo changed >> changed
343 346 $ echo added > added
344 347 $ hg add added
345 348 $ HGEDITOR=cat hg ci -A
346 349
347 350
348 351 HG: Enter commit message. Lines beginning with 'HG:' are removed.
349 352 HG: Leave message empty to abort commit.
350 353 HG: --
351 354 HG: user: test
352 355 HG: branch 'default'
353 356 HG: bookmark 'activebookmark'
354 357 HG: added added
355 358 HG: changed changed
356 359 HG: removed removed
357 360 abort: empty commit message
358 361 [255]
359 362
360 363 test saving last-message.txt
361 364
362 365 $ hg init sub
363 366 $ echo a > sub/a
364 367 $ hg -R sub add sub/a
365 368 $ cat > sub/.hg/hgrc <<EOF
366 369 > [hooks]
367 370 > precommit.test-saving-last-message = false
368 371 > EOF
369 372
370 373 $ echo 'sub = sub' > .hgsub
371 374 $ hg add .hgsub
372 375
373 376 $ cat > $TESTTMP/editor.sh <<EOF
374 377 > echo "==== before editing:"
375 378 > cat \$1
376 379 > echo "===="
377 380 > echo "test saving last-message.txt" >> \$1
378 381 > EOF
379 382
380 383 $ rm -f .hg/last-message.txt
381 384 $ HGEDITOR="sh $TESTTMP/editor.sh" hg commit -S -q
382 385 ==== before editing:
383 386
384 387
385 388 HG: Enter commit message. Lines beginning with 'HG:' are removed.
386 389 HG: Leave message empty to abort commit.
387 390 HG: --
388 391 HG: user: test
389 392 HG: branch 'default'
390 393 HG: bookmark 'activebookmark'
391 394 HG: subrepo sub
392 395 HG: added .hgsub
393 396 HG: added added
394 397 HG: changed .hgsubstate
395 398 HG: changed changed
396 399 HG: removed removed
397 400 ====
398 401 abort: precommit.test-saving-last-message hook exited with status 1 (in subrepository "sub")
399 402 [255]
400 403 $ cat .hg/last-message.txt
401 404
402 405
403 406 test saving last-message.txt
404 407
405 408 test that '[committemplate] changeset' definition and commit log
406 409 specific template keywords work well
407 410
408 411 $ cat >> .hg/hgrc <<EOF
409 412 > [committemplate]
410 413 > changeset.commit.normal = 'HG: this is "commit.normal" template
411 414 > HG: {extramsg}
412 415 > {if(activebookmark,
413 416 > "HG: bookmark '{activebookmark}' is activated\n",
414 417 > "HG: no bookmark is activated\n")}{subrepos %
415 418 > "HG: subrepo '{subrepo}' is changed\n"}'
416 419 >
417 420 > changeset.commit = HG: this is "commit" template
418 421 > HG: {extramsg}
419 422 > {if(activebookmark,
420 423 > "HG: bookmark '{activebookmark}' is activated\n",
421 424 > "HG: no bookmark is activated\n")}{subrepos %
422 425 > "HG: subrepo '{subrepo}' is changed\n"}
423 426 >
424 427 > changeset = HG: this is customized commit template
425 428 > HG: {extramsg}
426 429 > {if(activebookmark,
427 430 > "HG: bookmark '{activebookmark}' is activated\n",
428 431 > "HG: no bookmark is activated\n")}{subrepos %
429 432 > "HG: subrepo '{subrepo}' is changed\n"}
430 433 > EOF
431 434
432 435 $ hg init sub2
433 436 $ echo a > sub2/a
434 437 $ hg -R sub2 add sub2/a
435 438 $ echo 'sub2 = sub2' >> .hgsub
436 439
437 440 $ HGEDITOR=cat hg commit -S -q
438 441 HG: this is "commit.normal" template
439 442 HG: Leave message empty to abort commit.
440 443 HG: bookmark 'activebookmark' is activated
441 444 HG: subrepo 'sub' is changed
442 445 HG: subrepo 'sub2' is changed
443 446 abort: empty commit message
444 447 [255]
445 448
446 449 $ cat >> .hg/hgrc <<EOF
447 450 > [committemplate]
448 451 > changeset.commit.normal =
449 452 > # now, "changeset.commit" should be chosen for "hg commit"
450 453 > EOF
451 454
452 455 $ hg bookmark --inactive activebookmark
453 456 $ hg forget .hgsub
454 457 $ HGEDITOR=cat hg commit -q
455 458 HG: this is "commit" template
456 459 HG: Leave message empty to abort commit.
457 460 HG: no bookmark is activated
458 461 abort: empty commit message
459 462 [255]
460 463
461 464 $ cat >> .hg/hgrc <<EOF
462 465 > [committemplate]
463 466 > changeset.commit =
464 467 > # now, "changeset" should be chosen for "hg commit"
465 468 > EOF
466 469
467 470 $ HGEDITOR=cat hg commit -q
468 471 HG: this is customized commit template
469 472 HG: Leave message empty to abort commit.
470 473 HG: no bookmark is activated
471 474 abort: empty commit message
472 475 [255]
473 476
474 477 $ cat >> .hg/hgrc <<EOF
475 478 > [committemplate]
476 479 > changeset = {desc}
477 480 > HG: mods={file_mods}
478 481 > HG: adds={file_adds}
479 482 > HG: dels={file_dels}
480 483 > HG: files={files}
481 484 > HG:
482 485 > {splitlines(diff()) % 'HG: {line}\n'
483 486 > }HG:
484 487 > HG: mods={file_mods}
485 488 > HG: adds={file_adds}
486 489 > HG: dels={file_dels}
487 490 > HG: files={files}\n
488 491 > EOF
489 492 $ hg status -amr
490 493 M changed
491 494 A added
492 495 R removed
493 496 $ HGEDITOR=cat hg commit -q -e -m "foo bar" changed
494 497 foo bar
495 498 HG: mods=changed
496 499 HG: adds=
497 500 HG: dels=
498 501 HG: files=changed
499 502 HG:
500 503 HG: --- a/changed Thu Jan 01 00:00:00 1970 +0000
501 504 HG: +++ b/changed Thu Jan 01 00:00:00 1970 +0000
502 505 HG: @@ -1,1 +1,2 @@
503 506 HG: changed
504 507 HG: +changed
505 508 HG:
506 509 HG: mods=changed
507 510 HG: adds=
508 511 HG: dels=
509 512 HG: files=changed
510 513 $ hg status -amr
511 514 A added
512 515 R removed
513 516 $ hg parents --template "M {file_mods}\nA {file_adds}\nR {file_dels}\n"
514 517 M changed
515 518 A
516 519 R
517 520 $ hg rollback -q
518 521
519 522 $ cat >> .hg/hgrc <<EOF
520 523 > [committemplate]
521 524 > changeset = {desc}
522 525 > HG: mods={file_mods}
523 526 > HG: adds={file_adds}
524 527 > HG: dels={file_dels}
525 528 > HG: files={files}
526 529 > HG:
527 530 > {splitlines(diff("changed")) % 'HG: {line}\n'
528 531 > }HG:
529 532 > HG: mods={file_mods}
530 533 > HG: adds={file_adds}
531 534 > HG: dels={file_dels}
532 535 > HG: files={files}
533 536 > HG:
534 537 > {splitlines(diff("added")) % 'HG: {line}\n'
535 538 > }HG:
536 539 > HG: mods={file_mods}
537 540 > HG: adds={file_adds}
538 541 > HG: dels={file_dels}
539 542 > HG: files={files}
540 543 > HG:
541 544 > {splitlines(diff("removed")) % 'HG: {line}\n'
542 545 > }HG:
543 546 > HG: mods={file_mods}
544 547 > HG: adds={file_adds}
545 548 > HG: dels={file_dels}
546 549 > HG: files={files}\n
547 550 > EOF
548 551 $ HGEDITOR=cat hg commit -q -e -m "foo bar" added removed
549 552 foo bar
550 553 HG: mods=
551 554 HG: adds=added
552 555 HG: dels=removed
553 556 HG: files=added removed
554 557 HG:
555 558 HG:
556 559 HG: mods=
557 560 HG: adds=added
558 561 HG: dels=removed
559 562 HG: files=added removed
560 563 HG:
561 564 HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000
562 565 HG: +++ b/added Thu Jan 01 00:00:00 1970 +0000
563 566 HG: @@ -0,0 +1,1 @@
564 567 HG: +added
565 568 HG:
566 569 HG: mods=
567 570 HG: adds=added
568 571 HG: dels=removed
569 572 HG: files=added removed
570 573 HG:
571 574 HG: --- a/removed Thu Jan 01 00:00:00 1970 +0000
572 575 HG: +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
573 576 HG: @@ -1,1 +0,0 @@
574 577 HG: -removed
575 578 HG:
576 579 HG: mods=
577 580 HG: adds=added
578 581 HG: dels=removed
579 582 HG: files=added removed
580 583 $ hg status -amr
581 584 M changed
582 585 $ hg parents --template "M {file_mods}\nA {file_adds}\nR {file_dels}\n"
583 586 M
584 587 A added
585 588 R removed
586 589 $ hg rollback -q
587 590
588 591 $ cat >> .hg/hgrc <<EOF
589 592 > # disable customizing for subsequent tests
590 593 > [committemplate]
591 594 > changeset =
592 595 > EOF
593 596
594 597 $ cd ..
595 598
596 599
597 600 commit copy
598 601
599 602 $ hg init dir2
600 603 $ cd dir2
601 604 $ echo bleh > bar
602 605 $ hg add bar
603 606 $ hg ci -m 'add bar'
604 607
605 608 $ hg cp bar foo
606 609 $ echo >> bar
607 610 $ hg ci -m 'cp bar foo; change bar'
608 611
609 612 $ hg debugrename foo
610 613 foo renamed from bar:26d3ca0dfd18e44d796b564e38dd173c9668d3a9
611 614 $ hg debugindex bar
612 615 rev offset length ..... linkrev nodeid p1 p2 (re)
613 616 0 0 6 ..... 0 26d3ca0dfd18 000000000000 000000000000 (re)
614 617 1 6 7 ..... 1 d267bddd54f7 26d3ca0dfd18 000000000000 (re)
615 618
616 619 Test making empty commits
617 620 $ hg commit --config ui.allowemptycommit=True -m "empty commit"
618 621 $ hg log -r . -v --stat
619 622 changeset: 2:d809f3644287
620 623 tag: tip
621 624 user: test
622 625 date: Thu Jan 01 00:00:00 1970 +0000
623 626 description:
624 627 empty commit
625 628
626 629
627 630
628 631 verify pathauditor blocks evil filepaths
629 632 $ cat > evil-commit.py <<EOF
630 633 > from mercurial import ui, hg, context, node
631 634 > notrc = u".h\u200cg".encode('utf-8') + '/hgrc'
632 635 > u = ui.ui.load()
633 636 > r = hg.repository(u, '.')
634 637 > def filectxfn(repo, memctx, path):
635 638 > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
636 639 > c = context.memctx(r, [r['tip'].node(), node.nullid],
637 640 > 'evil', [notrc], filectxfn, 0)
638 641 > r.commitctx(c)
639 642 > EOF
640 643 $ $PYTHON evil-commit.py
641 644 #if windows
642 645 $ hg co --clean tip
643 646 abort: path contains illegal component: .h\xe2\x80\x8cg\\hgrc (esc)
644 647 [255]
645 648 #else
646 649 $ hg co --clean tip
647 650 abort: path contains illegal component: .h\xe2\x80\x8cg/hgrc (esc)
648 651 [255]
649 652 #endif
650 653
651 654 $ hg rollback -f
652 655 repository tip rolled back to revision 2 (undo commit)
653 656 $ cat > evil-commit.py <<EOF
654 657 > from mercurial import ui, hg, context, node
655 658 > notrc = "HG~1/hgrc"
656 659 > u = ui.ui.load()
657 660 > r = hg.repository(u, '.')
658 661 > def filectxfn(repo, memctx, path):
659 662 > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
660 663 > c = context.memctx(r, [r['tip'].node(), node.nullid],
661 664 > 'evil', [notrc], filectxfn, 0)
662 665 > r.commitctx(c)
663 666 > EOF
664 667 $ $PYTHON evil-commit.py
665 668 $ hg co --clean tip
666 669 abort: path contains illegal component: HG~1/hgrc (glob)
667 670 [255]
668 671
669 672 $ hg rollback -f
670 673 repository tip rolled back to revision 2 (undo commit)
671 674 $ cat > evil-commit.py <<EOF
672 675 > from mercurial import ui, hg, context, node
673 676 > notrc = "HG8B6C~2/hgrc"
674 677 > u = ui.ui.load()
675 678 > r = hg.repository(u, '.')
676 679 > def filectxfn(repo, memctx, path):
677 680 > return context.memfilectx(repo, path, '[hooks]\nupdate = echo owned')
678 681 > c = context.memctx(r, [r['tip'].node(), node.nullid],
679 682 > 'evil', [notrc], filectxfn, 0)
680 683 > r.commitctx(c)
681 684 > EOF
682 685 $ $PYTHON evil-commit.py
683 686 $ hg co --clean tip
684 687 abort: path contains illegal component: HG8B6C~2/hgrc (glob)
685 688 [255]
686 689
687 690 # test that an unmodified commit template message aborts
688 691
689 692 $ hg init unmodified_commit_template
690 693 $ cd unmodified_commit_template
691 694 $ echo foo > foo
692 695 $ hg add foo
693 696 $ hg commit -m "foo"
694 697 $ cat >> .hg/hgrc <<EOF
695 698 > [committemplate]
696 699 > changeset.commit = HI THIS IS NOT STRIPPED
697 700 > HG: this is customized commit template
698 701 > HG: {extramsg}
699 702 > {if(activebookmark,
700 703 > "HG: bookmark '{activebookmark}' is activated\n",
701 704 > "HG: no bookmark is activated\n")}{subrepos %
702 705 > "HG: subrepo '{subrepo}' is changed\n"}
703 706 > EOF
704 707 $ cat > $TESTTMP/notouching.sh <<EOF
705 708 > true
706 709 > EOF
707 710 $ echo foo2 > foo2
708 711 $ hg add foo2
709 712 $ HGEDITOR="sh $TESTTMP/notouching.sh" hg commit
710 713 abort: commit message unchanged
711 714 [255]
712 715
713 716 test that text below the --- >8 --- special string is ignored
714 717
715 718 $ cat <<'EOF' > $TESTTMP/lowercaseline.sh
716 719 > cat $1 | sed s/LINE/line/ | tee $1.new
717 720 > mv $1.new $1
718 721 > EOF
719 722
720 723 $ hg init ignore_below_special_string
721 724 $ cd ignore_below_special_string
722 725 $ echo foo > foo
723 726 $ hg add foo
724 727 $ hg commit -m "foo"
725 728 $ cat >> .hg/hgrc <<EOF
726 729 > [committemplate]
727 730 > changeset.commit = first LINE
728 731 > HG: this is customized commit template
729 732 > HG: {extramsg}
730 733 > HG: ------------------------ >8 ------------------------
731 734 > {diff()}
732 735 > EOF
733 736 $ echo foo2 > foo2
734 737 $ hg add foo2
735 738 $ HGEDITOR="sh $TESTTMP/notouching.sh" hg ci
736 739 abort: commit message unchanged
737 740 [255]
738 741 $ HGEDITOR="sh $TESTTMP/lowercaseline.sh" hg ci
739 742 first line
740 743 HG: this is customized commit template
741 744 HG: Leave message empty to abort commit.
742 745 HG: ------------------------ >8 ------------------------
743 746 diff -r e63c23eaa88a foo2
744 747 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
745 748 +++ b/foo2 Thu Jan 01 00:00:00 1970 +0000
746 749 @@ -0,0 +1,1 @@
747 750 +foo2
748 751 $ hg log -T '{desc}\n' -r .
749 752 first line
750 753
751 754 test that the special string --- >8 --- isn't used when not at the beginning of
752 755 a line
753 756
754 757 $ cat >> .hg/hgrc <<EOF
755 758 > [committemplate]
756 759 > changeset.commit = first LINE2
757 760 > another line HG: ------------------------ >8 ------------------------
758 761 > HG: this is customized commit template
759 762 > HG: {extramsg}
760 763 > HG: ------------------------ >8 ------------------------
761 764 > {diff()}
762 765 > EOF
763 766 $ echo foo >> foo
764 767 $ HGEDITOR="sh $TESTTMP/lowercaseline.sh" hg ci
765 768 first line2
766 769 another line HG: ------------------------ >8 ------------------------
767 770 HG: this is customized commit template
768 771 HG: Leave message empty to abort commit.
769 772 HG: ------------------------ >8 ------------------------
770 773 diff -r 3661b22b0702 foo
771 774 --- a/foo Thu Jan 01 00:00:00 1970 +0000
772 775 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
773 776 @@ -1,1 +1,2 @@
774 777 foo
775 778 +foo
776 779 $ hg log -T '{desc}\n' -r .
777 780 first line2
778 781 another line HG: ------------------------ >8 ------------------------
779 782
780 783 also test that this special string isn't accepted when there is some extra text
781 784 at the end
782 785
783 786 $ cat >> .hg/hgrc <<EOF
784 787 > [committemplate]
785 788 > changeset.commit = first LINE3
786 789 > HG: ------------------------ >8 ------------------------foobar
787 790 > second line
788 791 > HG: this is customized commit template
789 792 > HG: {extramsg}
790 793 > HG: ------------------------ >8 ------------------------
791 794 > {diff()}
792 795 > EOF
793 796 $ echo foo >> foo
794 797 $ HGEDITOR="sh $TESTTMP/lowercaseline.sh" hg ci
795 798 first line3
796 799 HG: ------------------------ >8 ------------------------foobar
797 800 second line
798 801 HG: this is customized commit template
799 802 HG: Leave message empty to abort commit.
800 803 HG: ------------------------ >8 ------------------------
801 804 diff -r ce648f5f066f foo
802 805 --- a/foo Thu Jan 01 00:00:00 1970 +0000
803 806 +++ b/foo Thu Jan 01 00:00:00 1970 +0000
804 807 @@ -1,2 +1,3 @@
805 808 foo
806 809 foo
807 810 +foo
808 811 $ hg log -T '{desc}\n' -r .
809 812 first line3
810 813 second line
811 814
812 815 $ cd ..
813 816
General Comments 0
You need to be logged in to leave comments. Login now