This instance will be upgraded to Heptapod 0.21.0rc2 on 2021-04-16 at 14:00 UTC+2 (a few minutes of down time)

test-commit.t 21 KB
Newer Older
Nicolas Dumazet's avatar
Nicolas Dumazet committed
1 2 3 4 5 6
commit date test

  $ hg init test
  $ cd test
  $ echo foo > foo
  $ hg add foo
7 8 9 10 11
  $ cat > $TESTTMP/checkeditform.sh <<EOF
  > env | grep HGEDITFORM
  > true
  > EOF
  $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg commit -m ""
12
  HGEDITFORM=commit.normal.normal
Nicolas Dumazet's avatar
Nicolas Dumazet committed
13
  abort: empty commit message
14
  [10]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
15 16 17
  $ hg commit -d '0 0' -m commit-1
  $ echo foo >> foo
  $ hg commit -d '1 4444444' -m commit-3
18
  hg: parse error: impossible time zone offset: 4444444
19
  [255]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
20
  $ hg commit -d '1	15.1' -m commit-4
21
  hg: parse error: invalid date: '1\t15.1'
22
  [255]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
23
  $ hg commit -d 'foo bar' -m commit-5
24
  hg: parse error: invalid date: 'foo bar'
25
  [255]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
26 27
  $ hg commit -d ' 1 4444' -m commit-6
  $ hg commit -d '111111111111 0' -m commit-7
28
  hg: parse error: date exceeds 32 bits: 111111111111
29
  [255]
30
  $ hg commit -d '-111111111111 0' -m commit-7
31
  hg: parse error: date exceeds 32 bits: -111111111111
32 33
  [255]
  $ echo foo >> foo
34
  $ hg commit -d '1901-12-13 20:45:52 +0000' -m commit-7-2
35
  $ echo foo >> foo
36
  $ hg commit -d '-2147483648 0' -m commit-7-3
37
  $ hg log -T '{rev} {date|isodatesec}\n' -l2
38 39 40
  3 1901-12-13 20:45:52 +0000
  2 1901-12-13 20:45:52 +0000
  $ hg commit -d '1901-12-13 20:45:51 +0000' -m commit-7
41
  hg: parse error: date exceeds 32 bits: -2147483649
42
  [255]
43
  $ hg commit -d '-2147483649 0' -m commit-7
44
  hg: parse error: date exceeds 32 bits: -2147483649
45
  [255]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
46 47 48 49 50 51

commit added file that has been deleted

  $ echo bar > bar
  $ hg add bar
  $ rm bar
52
  $ hg commit -m commit-8
53
  nothing changed (1 missing files, see 'hg status')
54
  [1]
55
  $ hg commit -m commit-8-2 bar
Nicolas Dumazet's avatar
Nicolas Dumazet committed
56
  abort: bar: file not found!
57
  [10]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
58 59 60 61 62 63

  $ hg -q revert -a --no-backup

  $ mkdir dir
  $ echo boo > dir/file
  $ hg add
64
  adding dir/file
Nicolas Dumazet's avatar
Nicolas Dumazet committed
65
  $ hg -v commit -m commit-9 dir
66
  committing files:
Nicolas Dumazet's avatar
Nicolas Dumazet committed
67
  dir/file
68 69
  committing manifest
  committing changelog
70
  committed changeset 4:1957363f1ced
Nicolas Dumazet's avatar
Nicolas Dumazet committed
71 72 73 74 75 76

  $ echo > dir.file
  $ hg add
  adding dir.file
  $ hg commit -m commit-10 dir dir.file
  abort: dir: no match under directory!
77
  [10]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
78 79 80 81 82 83 84

  $ echo >> dir/file
  $ mkdir bleh
  $ mkdir dir2
  $ cd bleh
  $ hg commit -m commit-11 .
  abort: bleh: no match under directory!
85
  [10]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
86 87
  $ hg commit -m commit-12 ../dir ../dir2
  abort: dir2: no match under directory!
88
  [10]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
89
  $ hg -v commit -m commit-13 ../dir
90
  committing files:
Nicolas Dumazet's avatar
Nicolas Dumazet committed
91
  dir/file
92 93
  committing manifest
  committing changelog
94
  committed changeset 5:a31d8f87544a
Nicolas Dumazet's avatar
Nicolas Dumazet committed
95 96 97
  $ cd ..

  $ hg commit -m commit-14 does-not-exist
98
  abort: does-not-exist: * (glob)
99
  [10]
100 101

#if symlink
Nicolas Dumazet's avatar
Nicolas Dumazet committed
102 103 104
  $ ln -s foo baz
  $ hg commit -m commit-15 baz
  abort: baz: file not tracked!
105
  [10]
106
  $ rm baz
107 108
#endif

Nicolas Dumazet's avatar
Nicolas Dumazet committed
109 110 111
  $ touch quux
  $ hg commit -m commit-16 quux
  abort: quux: file not tracked!
112
  [10]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
113 114
  $ echo >> dir/file
  $ hg -v commit -m commit-17 dir/file
115
  committing files:
Nicolas Dumazet's avatar
Nicolas Dumazet committed
116
  dir/file
117 118
  committing manifest
  committing changelog
119
  committed changeset 6:32d054c9d085
Nicolas Dumazet's avatar
Nicolas Dumazet committed
120 121 122 123

An empty date was interpreted as epoch origin

  $ echo foo >> foo
124
  $ hg commit -d '' -m commit-no-date --config devel.default-date=
Nicolas Dumazet's avatar
Nicolas Dumazet committed
125
  $ hg tip --template '{date|isodate}\n' | grep '1970'
126
  [1]
127

128 129 130 131 132 133
Using the advanced --extra flag

  $ echo "[extensions]" >> $HGRCPATH
  $ echo "commitextras=" >> $HGRCPATH
  $ hg status
  ? quux
134 135 136 137
  $ hg add quux
  $ hg commit -m "adding internal used extras" --extra amend_source=hash
  abort: key 'amend_source' is used internally, can't be set manually
  [255]
138 139 140
  $ hg commit -m "special chars in extra" --extra id@phab=214
  abort: keys can only contain ascii letters, digits, '_' and '-'
  [255]
141 142 143
  $ hg commit -m "empty key" --extra =value
  abort: unable to parse '=value', keys can't be empty
  [255]
144 145 146 147 148 149
  $ hg commit -m "adding extras" --extra sourcehash=foo --extra oldhash=bar
  $ hg log -r . -T '{extras % "{extra}\n"}'
  branch=default
  oldhash=bar
  sourcehash=foo

150 151 152 153 154 155 156 157
Failed commit with --addremove should not update dirstate

  $ echo foo > newfile
  $ hg status
  ? newfile
  $ HGEDITOR=false hg ci --addremove
  adding newfile
  abort: edit failed: false exited with status 1
158
  [250]
159
  $ hg status
160
  ? newfile
161

162 163 164 165 166
Make sure we do not obscure unknown requires file entries (issue2649)

  $ echo foo >> foo
  $ echo fake >> .hg/requires
  $ hg commit -m bla
167
  abort: repository requires features unknown to this Mercurial: fake!
168
  (see https://mercurial-scm.org/wiki/MissingRequirement for more information)
169 170
  [255]

Nicolas Dumazet's avatar
Nicolas Dumazet committed
171 172 173 174 175 176 177 178 179 180 181 182
  $ cd ..


partial subdir commit test

  $ hg init test2
  $ cd test2
  $ mkdir foo
  $ echo foo > foo/foo
  $ mkdir bar
  $ echo bar > bar/bar
  $ hg add
183 184
  adding bar/bar
  adding foo/foo
185 186 187 188 189 190 191 192 193 194 195 196
  $ HGEDITOR=cat hg ci -e -m commit-subdir-1 foo
  commit-subdir-1
  
  
  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
  HG: Leave message empty to abort commit.
  HG: --
  HG: user: test
  HG: branch 'default'
  HG: added foo/foo


197
  $ hg ci -m commit-subdir-2 bar
Nicolas Dumazet's avatar
Nicolas Dumazet committed
198 199 200 201

subdir log 1

  $ hg log -v foo
202
  changeset:   0:f97e73a25882
Nicolas Dumazet's avatar
Nicolas Dumazet committed
203
  user:        test
204
  date:        Thu Jan 01 00:00:00 1970 +0000
Nicolas Dumazet's avatar
Nicolas Dumazet committed
205 206 207 208 209 210 211 212 213
  files:       foo/foo
  description:
  commit-subdir-1
  
  

subdir log 2

  $ hg log -v bar
214
  changeset:   1:aa809156d50d
Nicolas Dumazet's avatar
Nicolas Dumazet committed
215 216
  tag:         tip
  user:        test
217
  date:        Thu Jan 01 00:00:00 1970 +0000
Nicolas Dumazet's avatar
Nicolas Dumazet committed
218 219 220 221 222 223 224 225 226
  files:       bar/bar
  description:
  commit-subdir-2
  
  

full log

  $ hg log -v
227
  changeset:   1:aa809156d50d
Nicolas Dumazet's avatar
Nicolas Dumazet committed
228 229
  tag:         tip
  user:        test
230
  date:        Thu Jan 01 00:00:00 1970 +0000
Nicolas Dumazet's avatar
Nicolas Dumazet committed
231 232 233 234 235
  files:       bar/bar
  description:
  commit-subdir-2
  
  
236
  changeset:   0:f97e73a25882
Nicolas Dumazet's avatar
Nicolas Dumazet committed
237
  user:        test
238
  date:        Thu Jan 01 00:00:00 1970 +0000
Nicolas Dumazet's avatar
Nicolas Dumazet committed
239 240 241 242 243 244 245 246 247 248 249
  files:       foo/foo
  description:
  commit-subdir-1
  
  
  $ cd ..


dot and subdir commit test

  $ hg init test3
250
  $ echo commit-foo-subdir > commit-log-test
Nicolas Dumazet's avatar
Nicolas Dumazet committed
251 252 253 254
  $ cd test3
  $ mkdir foo
  $ echo foo content > foo/plain-file
  $ hg add foo/plain-file
255 256 257 258 259 260 261 262 263 264 265 266
  $ HGEDITOR=cat hg ci --edit -l ../commit-log-test foo
  commit-foo-subdir
  
  
  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
  HG: Leave message empty to abort commit.
  HG: --
  HG: user: test
  HG: branch 'default'
  HG: added foo/plain-file


Nicolas Dumazet's avatar
Nicolas Dumazet committed
267
  $ echo modified foo content > foo/plain-file
268
  $ hg ci -m commit-foo-dot .
Nicolas Dumazet's avatar
Nicolas Dumazet committed
269 270 271 272

full log

  $ hg log -v
273
  changeset:   1:95b38e3a5b2e
Nicolas Dumazet's avatar
Nicolas Dumazet committed
274 275
  tag:         tip
  user:        test
276
  date:        Thu Jan 01 00:00:00 1970 +0000
Nicolas Dumazet's avatar
Nicolas Dumazet committed
277 278 279 280 281
  files:       foo/plain-file
  description:
  commit-foo-dot
  
  
282
  changeset:   0:65d4e9386227
Nicolas Dumazet's avatar
Nicolas Dumazet committed
283
  user:        test
284
  date:        Thu Jan 01 00:00:00 1970 +0000
Nicolas Dumazet's avatar
Nicolas Dumazet committed
285 286 287 288 289 290 291 292 293 294
  files:       foo/plain-file
  description:
  commit-foo-subdir
  
  

subdir log

  $ cd foo
  $ hg log .
295
  changeset:   1:95b38e3a5b2e
Nicolas Dumazet's avatar
Nicolas Dumazet committed
296 297
  tag:         tip
  user:        test
298
  date:        Thu Jan 01 00:00:00 1970 +0000
Nicolas Dumazet's avatar
Nicolas Dumazet committed
299 300
  summary:     commit-foo-dot
  
301
  changeset:   0:65d4e9386227
Nicolas Dumazet's avatar
Nicolas Dumazet committed
302
  user:        test
303
  date:        Thu Jan 01 00:00:00 1970 +0000
Nicolas Dumazet's avatar
Nicolas Dumazet committed
304 305 306 307 308
  summary:     commit-foo-subdir
  
  $ cd ..
  $ cd ..

309 310
Issue1049: Hg permits partial commit of merge without warning

Nicolas Dumazet's avatar
Nicolas Dumazet committed
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
  $ hg init issue1049
  $ cd issue1049
  $ echo a > a
  $ hg ci -Ama
  adding a
  $ echo a >> a
  $ hg ci -mb
  $ hg up 0
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ echo b >> a
  $ hg ci -mc
  created new head
  $ HGMERGE=true hg merge
  merging a
  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
  (branch merge, don't forget to commit)

should fail because we are specifying a file name

  $ hg ci -mmerge a
  abort: cannot partially commit a merge (do not specify files or patterns)
332
  [255]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
333 334 335 336 337

should fail because we are specifying a pattern

  $ hg ci -mmerge -I a
  abort: cannot partially commit a merge (do not specify files or patterns)
338
  [255]
Nicolas Dumazet's avatar
Nicolas Dumazet committed
339 340 341

should succeed

342 343
  $ HGEDITOR="sh $TESTTMP/checkeditform.sh" hg ci -mmerge --edit
  HGEDITFORM=commit.normal.merge
Nicolas Dumazet's avatar
Nicolas Dumazet committed
344 345 346 347 348 349 350 351 352
  $ cd ..


test commit message content

  $ hg init commitmsg
  $ cd commitmsg
  $ echo changed > changed
  $ echo removed > removed
353
  $ hg book activebookmark
Nicolas Dumazet's avatar
Nicolas Dumazet committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367
  $ hg ci -qAm init

  $ hg rm removed
  $ echo changed >> changed
  $ echo added > added
  $ hg add added
  $ HGEDITOR=cat hg ci -A
  
  
  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
  HG: Leave message empty to abort commit.
  HG: --
  HG: user: test
  HG: branch 'default'
368
  HG: bookmark 'activebookmark'
Nicolas Dumazet's avatar
Nicolas Dumazet committed
369 370 371 372
  HG: added added
  HG: changed changed
  HG: removed removed
  abort: empty commit message
373
  [10]
374 375 376 377 378 379 380 381 382 383 384 385 386 387

test saving last-message.txt

  $ hg init sub
  $ echo a > sub/a
  $ hg -R sub add sub/a
  $ cat > sub/.hg/hgrc <<EOF
  > [hooks]
  > precommit.test-saving-last-message = false
  > EOF

  $ echo 'sub = sub' > .hgsub
  $ hg add .hgsub

388
  $ cat > $TESTTMP/editor.sh <<EOF
389 390 391 392 393 394 395
  > echo "==== before editing:"
  > cat \$1
  > echo "===="
  > echo "test saving last-message.txt" >> \$1
  > EOF

  $ rm -f .hg/last-message.txt
396
  $ HGEDITOR="sh $TESTTMP/editor.sh" hg commit -S -q
397 398 399 400 401 402 403 404
  ==== before editing:
  
  
  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
  HG: Leave message empty to abort commit.
  HG: --
  HG: user: test
  HG: branch 'default'
405
  HG: bookmark 'activebookmark'
406 407 408 409 410 411 412
  HG: subrepo sub
  HG: added .hgsub
  HG: added added
  HG: changed .hgsubstate
  HG: changed changed
  HG: removed removed
  ====
413
  abort: precommit.test-saving-last-message hook exited with status 1 (in subrepository "sub")
414 415 416 417 418 419
  [255]
  $ cat .hg/last-message.txt
  
  
  test saving last-message.txt

420 421 422 423 424
test that '[committemplate] changeset' definition and commit log
specific template keywords work well

  $ cat >> .hg/hgrc <<EOF
  > [committemplate]
425
  > changeset.commit.normal = 'HG: this is "commit.normal" template
426
  >     HG: {extramsg}
427 428
  >     {if(activebookmark,
  >    "HG: bookmark '{activebookmark}' is activated\n",
429
  >    "HG: no bookmark is activated\n")}{subrepos %
430
  >    "HG: subrepo '{subrepo}' is changed\n"}'
431 432 433
  > 
  > changeset.commit = HG: this is "commit" template
  >     HG: {extramsg}
434 435
  >     {if(activebookmark,
  >    "HG: bookmark '{activebookmark}' is activated\n",
436 437 438
  >    "HG: no bookmark is activated\n")}{subrepos %
  >    "HG: subrepo '{subrepo}' is changed\n"}
  > 
439 440
  > changeset = HG: this is customized commit template
  >     HG: {extramsg}
441 442
  >     {if(activebookmark,
  >    "HG: bookmark '{activebookmark}' is activated\n",
443 444 445 446 447 448 449 450 451 452
  >    "HG: no bookmark is activated\n")}{subrepos %
  >    "HG: subrepo '{subrepo}' is changed\n"}
  > EOF

  $ hg init sub2
  $ echo a > sub2/a
  $ hg -R sub2 add sub2/a
  $ echo 'sub2 = sub2' >> .hgsub

  $ HGEDITOR=cat hg commit -S -q
453
  HG: this is "commit.normal" template
454
  HG: Leave message empty to abort commit.
455
  HG: bookmark 'activebookmark' is activated
456 457 458
  HG: subrepo 'sub' is changed
  HG: subrepo 'sub2' is changed
  abort: empty commit message
459
  [10]
460

461 462 463 464 465 466
  $ cat >> .hg/hgrc <<EOF
  > [committemplate]
  > changeset.commit.normal =
  > # now, "changeset.commit" should be chosen for "hg commit"
  > EOF

467
  $ hg bookmark --inactive activebookmark
468
  $ hg forget .hgsub
469 470 471 472 473
  $ HGEDITOR=cat hg commit -q
  HG: this is "commit" template
  HG: Leave message empty to abort commit.
  HG: no bookmark is activated
  abort: empty commit message
474
  [10]
475 476 477 478 479 480 481

  $ cat >> .hg/hgrc <<EOF
  > [committemplate]
  > changeset.commit =
  > # now, "changeset" should be chosen for "hg commit"
  > EOF

482 483 484 485 486
  $ HGEDITOR=cat hg commit -q
  HG: this is customized commit template
  HG: Leave message empty to abort commit.
  HG: no bookmark is activated
  abort: empty commit message
487
  [10]
488

489 490 491
  $ cat >> .hg/hgrc <<EOF
  > [committemplate]
  > changeset = {desc}
492 493 494
  >     HG: mods={file_mods}
  >     HG: adds={file_adds}
  >     HG: dels={file_dels}
495 496
  >     HG: files={files}
  >     HG:
497
  >     {splitlines(diff()) % 'HG: {line}\n'
498
  >    }HG:
499 500 501
  >     HG: mods={file_mods}
  >     HG: adds={file_adds}
  >     HG: dels={file_dels}
502 503 504 505 506 507 508 509
  >     HG: files={files}\n
  > EOF
  $ hg status -amr
  M changed
  A added
  R removed
  $ HGEDITOR=cat hg commit -q -e -m "foo bar" changed
  foo bar
510 511 512
  HG: mods=changed
  HG: adds=
  HG: dels=
513 514
  HG: files=changed
  HG:
515
  HG: diff -r d2313f97106f changed
516 517 518 519 520
  HG: --- a/changed	Thu Jan 01 00:00:00 1970 +0000
  HG: +++ b/changed	Thu Jan 01 00:00:00 1970 +0000
  HG: @@ -1,1 +1,2 @@
  HG:  changed
  HG: +changed
521
  HG:
522 523 524
  HG: mods=changed
  HG: adds=
  HG: dels=
525 526 527 528 529 530 531 532 533 534
  HG: files=changed
  $ hg status -amr
  A added
  R removed
  $ hg parents --template "M {file_mods}\nA {file_adds}\nR {file_dels}\n"
  M changed
  A 
  R 
  $ hg rollback -q

535 536 537
  $ cat >> .hg/hgrc <<EOF
  > [committemplate]
  > changeset = {desc}
538 539 540
  >     HG: mods={file_mods}
  >     HG: adds={file_adds}
  >     HG: dels={file_dels}
541 542 543 544
  >     HG: files={files}
  >     HG:
  >     {splitlines(diff("changed")) % 'HG: {line}\n'
  >    }HG:
545 546 547
  >     HG: mods={file_mods}
  >     HG: adds={file_adds}
  >     HG: dels={file_dels}
548 549 550 551
  >     HG: files={files}
  >     HG:
  >     {splitlines(diff("added")) % 'HG: {line}\n'
  >    }HG:
552 553 554
  >     HG: mods={file_mods}
  >     HG: adds={file_adds}
  >     HG: dels={file_dels}
555 556 557 558
  >     HG: files={files}
  >     HG:
  >     {splitlines(diff("removed")) % 'HG: {line}\n'
  >    }HG:
559 560 561
  >     HG: mods={file_mods}
  >     HG: adds={file_adds}
  >     HG: dels={file_dels}
562 563 564 565
  >     HG: files={files}\n
  > EOF
  $ HGEDITOR=cat hg commit -q -e -m "foo bar" added removed
  foo bar
566 567 568
  HG: mods=
  HG: adds=added
  HG: dels=removed
569 570 571
  HG: files=added removed
  HG:
  HG:
572 573 574
  HG: mods=
  HG: adds=added
  HG: dels=removed
575 576
  HG: files=added removed
  HG:
577
  HG: diff -r d2313f97106f added
578 579 580 581 582
  HG: --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
  HG: +++ b/added	Thu Jan 01 00:00:00 1970 +0000
  HG: @@ -0,0 +1,1 @@
  HG: +added
  HG:
583 584 585
  HG: mods=
  HG: adds=added
  HG: dels=removed
586 587
  HG: files=added removed
  HG:
588
  HG: diff -r d2313f97106f removed
589 590 591 592 593
  HG: --- a/removed	Thu Jan 01 00:00:00 1970 +0000
  HG: +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
  HG: @@ -1,1 +0,0 @@
  HG: -removed
  HG:
594 595 596
  HG: mods=
  HG: adds=added
  HG: dels=removed
597 598 599 600 601 602 603 604 605
  HG: files=added removed
  $ hg status -amr
  M changed
  $ hg parents --template "M {file_mods}\nA {file_adds}\nR {file_dels}\n"
  M 
  A added
  R removed
  $ hg rollback -q

606 607 608 609 610 611
  $ cat >> .hg/hgrc <<EOF
  > # disable customizing for subsequent tests
  > [committemplate]
  > changeset =
  > EOF

612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
  $ cd ..


commit copy

  $ hg init dir2
  $ cd dir2
  $ echo bleh > bar
  $ hg add bar
  $ hg ci -m 'add bar'

  $ hg cp bar foo
  $ echo >> bar
  $ hg ci -m 'cp bar foo; change bar'

  $ hg debugrename foo
  foo renamed from bar:26d3ca0dfd18e44d796b564e38dd173c9668d3a9
  $ hg debugindex bar
630 631 632
     rev linkrev nodeid       p1           p2
       0       0 26d3ca0dfd18 000000000000 000000000000
       1       1 d267bddd54f7 26d3ca0dfd18 000000000000
kiilerix's avatar
kiilerix committed
633

634 635 636 637 638 639 640 641 642 643 644 645
Test making empty commits
  $ hg commit --config ui.allowemptycommit=True -m "empty commit"
  $ hg log -r . -v --stat
  changeset:   2:d809f3644287
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  description:
  empty commit
  
  
  
646 647
verify pathauditor blocks evil filepaths
  $ cat > evil-commit.py <<EOF
648 649
  > from __future__ import absolute_import
  > from mercurial import context, hg, node, ui as uimod
650
  > notrc = u".h\u200cg".encode('utf-8') + b'/hgrc'
651
  > u = uimod.ui.load()
652
  > r = hg.repository(u, b'.')
653
  > def filectxfn(repo, memctx, path):
654
  >     return context.memfilectx(repo, memctx, path,
655
  >         b'[hooks]\nupdate = echo owned')
656
  > c = context.memctx(r, [r.changelog.tip(), node.nullid],
657
  >                    b'evil', [notrc], filectxfn, 0)
658 659
  > r.commitctx(c)
  > EOF
Matt Harbison's avatar
Matt Harbison committed
660
  $ "$PYTHON" evil-commit.py
661 662 663 664 665
#if windows
  $ hg co --clean tip
  abort: path contains illegal component: .h\xe2\x80\x8cg\\hgrc (esc)
  [255]
#else
666 667 668
  $ hg co --clean tip
  abort: path contains illegal component: .h\xe2\x80\x8cg/hgrc (esc)
  [255]
669
#endif
670

671
  $ hg rollback -f
672
  repository tip rolled back to revision 2 (undo commit)
673
  $ cat > evil-commit.py <<EOF
674 675
  > from __future__ import absolute_import
  > from mercurial import context, hg, node, ui as uimod
676
  > notrc = b"HG~1/hgrc"
677
  > u = uimod.ui.load()
678
  > r = hg.repository(u, b'.')
679
  > def filectxfn(repo, memctx, path):
680
  >     return context.memfilectx(repo, memctx, path,
681 682 683
  >         b'[hooks]\nupdate = echo owned')
  > c = context.memctx(r, [r[b'tip'].node(), node.nullid],
  >                    b'evil', [notrc], filectxfn, 0)
684 685
  > r.commitctx(c)
  > EOF
Matt Harbison's avatar
Matt Harbison committed
686
  $ "$PYTHON" evil-commit.py
687
  $ hg co --clean tip
688
  abort: path contains illegal component: HG~1/hgrc
689 690 691
  [255]

  $ hg rollback -f
692
  repository tip rolled back to revision 2 (undo commit)
693
  $ cat > evil-commit.py <<EOF
694 695
  > from __future__ import absolute_import
  > from mercurial import context, hg, node, ui as uimod
696
  > notrc = b"HG8B6C~2/hgrc"
697
  > u = uimod.ui.load()
698
  > r = hg.repository(u, b'.')
699
  > def filectxfn(repo, memctx, path):
700
  >     return context.memfilectx(repo, memctx, path,
701 702 703
  >         b'[hooks]\nupdate = echo owned')
  > c = context.memctx(r, [r[b'tip'].node(), node.nullid],
  >                    b'evil', [notrc], filectxfn, 0)
704 705
  > r.commitctx(c)
  > EOF
Matt Harbison's avatar
Matt Harbison committed
706
  $ "$PYTHON" evil-commit.py
707
  $ hg co --clean tip
708
  abort: path contains illegal component: HG8B6C~2/hgrc
709
  [255]
710

711 712
  $ cd ..

713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
# test that an unmodified commit template message aborts

  $ hg init unmodified_commit_template
  $ cd unmodified_commit_template
  $ echo foo > foo
  $ hg add foo
  $ hg commit -m "foo"
  $ cat >> .hg/hgrc <<EOF
  > [committemplate]
  > changeset.commit = HI THIS IS NOT STRIPPED
  >     HG: this is customized commit template
  >     HG: {extramsg}
  >     {if(activebookmark,
  >    "HG: bookmark '{activebookmark}' is activated\n",
  >    "HG: no bookmark is activated\n")}{subrepos %
  >    "HG: subrepo '{subrepo}' is changed\n"}
  > EOF
  $ cat > $TESTTMP/notouching.sh <<EOF
  > true
  > EOF
  $ echo foo2 > foo2
  $ hg add foo2
  $ HGEDITOR="sh $TESTTMP/notouching.sh" hg commit
  abort: commit message unchanged
737
  [10]
738

739 740
  $ cd ..

741 742
test that text below the --- >8 --- special string is ignored

743 744 745 746 747
  $ cat <<'EOF' > $TESTTMP/lowercaseline.sh
  > cat $1 | sed s/LINE/line/ | tee $1.new
  > mv $1.new $1
  > EOF

748 749 750 751 752 753 754
  $ hg init ignore_below_special_string
  $ cd ignore_below_special_string
  $ echo foo > foo
  $ hg add foo
  $ hg commit -m "foo"
  $ cat >> .hg/hgrc <<EOF
  > [committemplate]
755
  > changeset.commit = first LINE
756 757 758 759 760 761 762
  >     HG: this is customized commit template
  >     HG: {extramsg}
  >     HG: ------------------------ >8 ------------------------
  >     {diff()}
  > EOF
  $ echo foo2 > foo2
  $ hg add foo2
763 764
  $ HGEDITOR="sh $TESTTMP/notouching.sh" hg ci
  abort: commit message unchanged
765
  [10]
766
  $ HGEDITOR="sh $TESTTMP/lowercaseline.sh" hg ci
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
  first line
  HG: this is customized commit template
  HG: Leave message empty to abort commit.
  HG: ------------------------ >8 ------------------------
  diff -r e63c23eaa88a foo2
  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
  +++ b/foo2	Thu Jan 01 00:00:00 1970 +0000
  @@ -0,0 +1,1 @@
  +foo2
  $ hg log -T '{desc}\n' -r .
  first line

test that the special string --- >8 --- isn't used when not at the beginning of
a line

  $ cat >> .hg/hgrc <<EOF
  > [committemplate]
784
  > changeset.commit = first LINE2
785 786 787 788 789 790 791
  >     another line HG: ------------------------ >8 ------------------------
  >     HG: this is customized commit template
  >     HG: {extramsg}
  >     HG: ------------------------ >8 ------------------------
  >     {diff()}
  > EOF
  $ echo foo >> foo
792
  $ HGEDITOR="sh $TESTTMP/lowercaseline.sh" hg ci
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812
  first line2
  another line HG: ------------------------ >8 ------------------------
  HG: this is customized commit template
  HG: Leave message empty to abort commit.
  HG: ------------------------ >8 ------------------------
  diff -r 3661b22b0702 foo
  --- a/foo	Thu Jan 01 00:00:00 1970 +0000
  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
  @@ -1,1 +1,2 @@
   foo
  +foo
  $ hg log -T '{desc}\n' -r .
  first line2
  another line HG: ------------------------ >8 ------------------------

also test that this special string isn't accepted when there is some extra text
at the end

  $ cat >> .hg/hgrc <<EOF
  > [committemplate]
813
  > changeset.commit = first LINE3
814 815 816 817 818 819 820 821
  >     HG: ------------------------ >8 ------------------------foobar
  >     second line
  >     HG: this is customized commit template
  >     HG: {extramsg}
  >     HG: ------------------------ >8 ------------------------
  >     {diff()}
  > EOF
  $ echo foo >> foo
822
  $ HGEDITOR="sh $TESTTMP/lowercaseline.sh" hg ci
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
  first line3
  HG: ------------------------ >8 ------------------------foobar
  second line
  HG: this is customized commit template
  HG: Leave message empty to abort commit.
  HG: ------------------------ >8 ------------------------
  diff -r ce648f5f066f foo
  --- a/foo	Thu Jan 01 00:00:00 1970 +0000
  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
  @@ -1,2 +1,3 @@
   foo
   foo
  +foo
  $ hg log -T '{desc}\n' -r .
  first line3
  second line

840
  $ cd ..
841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879

testing commands.commit.post-status config option

  $ hg init ci-post-st
  $ cd ci-post-st
  $ echo '[commands]' > .hg/hgrc
  $ echo 'commit.post-status = 1' >> .hg/hgrc

  $ echo 'ignored-file' > .hgignore
  $ hg ci -qAm 0

  $ echo 'c' > clean-file
  $ echo 'a' > added-file
  $ echo '?' > unknown-file
  $ echo 'i' > ignored-file
  $ hg add clean-file added-file
  $ hg ci -m 1 clean-file
  A added-file
  ? unknown-file
  $ hg st -mardu
  A added-file
  ? unknown-file

  $ touch modified-file
  $ hg add modified-file
  $ hg ci -m 2 modified-file -q

  $ echo 'm' > modified-file
  $ hg ci --amend -m 'reworded' -X 're:'
  saved backup bundle to $TESTTMP/ci-post-st/.hg/strip-backup/*-amend.hg (glob)
  M modified-file
  A added-file
  ? unknown-file
  $ hg st -mardu
  M modified-file
  A added-file
  ? unknown-file

  $ cd ..