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