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