##// END OF EJS Templates
record: allow editing new files (issue4304)...
Laurent Charignon -
r24235:79fceed6 default
parent child Browse files
Show More
@@ -76,7 +76,7 b' class header(object):'
76 """
76 """
77 diffgit_re = re.compile('diff --git a/(.*) b/(.*)$')
77 diffgit_re = re.compile('diff --git a/(.*) b/(.*)$')
78 diff_re = re.compile('diff -r .* (.*)$')
78 diff_re = re.compile('diff -r .* (.*)$')
79 allhunks_re = re.compile('(?:index|new file|deleted file) ')
79 allhunks_re = re.compile('(?:index|deleted file) ')
80 pretty_re = re.compile('(?:new file|deleted file) ')
80 pretty_re = re.compile('(?:new file|deleted file) ')
81 special_re = re.compile('(?:index|new|deleted|copy|rename) ')
81 special_re = re.compile('(?:index|new|deleted|copy|rename) ')
82
82
@@ -522,9 +522,9 b' def dorecord(ui, repo, commitfunc, cmdsu'
522 diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True)
522 diffopts = patch.difffeatureopts(ui, opts=opts, whitespace=True)
523 diffopts.nodates = True
523 diffopts.nodates = True
524 diffopts.git = True
524 diffopts.git = True
525 chunks = patch.diff(repo, changes=status, opts=diffopts)
525 originalchunks = patch.diff(repo, changes=status, opts=diffopts)
526 fp = cStringIO.StringIO()
526 fp = cStringIO.StringIO()
527 fp.write(''.join(chunks))
527 fp.write(''.join(originalchunks))
528 fp.seek(0)
528 fp.seek(0)
529
529
530 # 1. filter patch, so we have intending-to apply subset of it
530 # 1. filter patch, so we have intending-to apply subset of it
@@ -548,13 +548,22 b' def dorecord(ui, repo, commitfunc, cmdsu'
548 ui.status(_('no changes to record\n'))
548 ui.status(_('no changes to record\n'))
549 return 0
549 return 0
550
550
551 newandmodifiedfiles = set()
552 for h in chunks:
553 ishunk = isinstance(h, hunk)
554 isnew = h.filename() in status.added
555 if ishunk and isnew and not h in originalchunks:
556 newandmodifiedfiles.add(h.filename())
557
551 modified = set(status.modified)
558 modified = set(status.modified)
552
559
553 # 2. backup changed files, so we can restore them in the end
560 # 2. backup changed files, so we can restore them in the end
561
554 if backupall:
562 if backupall:
555 tobackup = changed
563 tobackup = changed
556 else:
564 else:
557 tobackup = [f for f in newfiles if f in modified]
565 tobackup = [f for f in newfiles
566 if f in modified or f in newandmodifiedfiles]
558
567
559 backups = {}
568 backups = {}
560 if tobackup:
569 if tobackup:
@@ -577,11 +586,14 b' def dorecord(ui, repo, commitfunc, cmdsu'
577
586
578 fp = cStringIO.StringIO()
587 fp = cStringIO.StringIO()
579 for c in chunks:
588 for c in chunks:
580 if c.filename() in backups:
589 fname = c.filename()
590 if fname in backups or fname in newandmodifiedfiles:
581 c.write(fp)
591 c.write(fp)
582 dopatch = fp.tell()
592 dopatch = fp.tell()
583 fp.seek(0)
593 fp.seek(0)
584
594
595 [os.unlink(c) for c in newandmodifiedfiles]
596
585 # 3a. apply filtered patch to clean repo (clean)
597 # 3a. apply filtered patch to clean repo (clean)
586 if backups:
598 if backups:
587 hg.revert(repo, repo.dirstate.p1(),
599 hg.revert(repo, repo.dirstate.p1(),
@@ -473,18 +473,24 b' record added file alone'
473
473
474 $ hg -v record -l msg -d '12 2' r<<EOF
474 $ hg -v record -l msg -d '12 2' r<<EOF
475 > y
475 > y
476 > y
476 > EOF
477 > EOF
477 diff --git a/r b/r
478 diff --git a/r b/r
478 new file mode 100644
479 new file mode 100644
479 examine changes to 'r'? [Ynesfdaq?] y
480 examine changes to 'r'? [Ynesfdaq?] y
480
481
482 @@ -0,0 +1,1 @@
483 +$Id$
484 record this change to 'r'? [Ynesfdaq?] y
485
486 resolving manifests
487 patching file r
481 committing files:
488 committing files:
482 r
489 r
483 committing manifest
490 committing manifest
484 committing changelog
491 committing changelog
485 committed changeset 3:82a2f715724d
492 committed changeset 3:82a2f715724d
486 overwriting r expanding keywords
493 overwriting r expanding keywords
487 - status call required for dirstate.normallookup() check
488 $ hg status r
494 $ hg status r
489 $ hg --verbose rollback
495 $ hg --verbose rollback
490 repository tip rolled back to revision 2 (undo commit)
496 repository tip rolled back to revision 2 (undo commit)
@@ -501,11 +507,18 b' record added keyword ignored file'
501 $ hg add i
507 $ hg add i
502 $ hg --verbose record -d '13 1' -m recignored<<EOF
508 $ hg --verbose record -d '13 1' -m recignored<<EOF
503 > y
509 > y
510 > y
504 > EOF
511 > EOF
505 diff --git a/i b/i
512 diff --git a/i b/i
506 new file mode 100644
513 new file mode 100644
507 examine changes to 'i'? [Ynesfdaq?] y
514 examine changes to 'i'? [Ynesfdaq?] y
508
515
516 @@ -0,0 +1,1 @@
517 +$Id$
518 record this change to 'i'? [Ynesfdaq?] y
519
520 resolving manifests
521 patching file i
509 committing files:
522 committing files:
510 i
523 i
511 committing manifest
524 committing manifest
@@ -295,6 +295,11 b' handle subrepos safely on qrecord'
295 new file mode 100644
295 new file mode 100644
296 examine changes to '.hgsub'? [Ynesfdaq?] y
296 examine changes to '.hgsub'? [Ynesfdaq?] y
297
297
298 @@ -0,0 +1,1 @@
299 +sub = sub
300 record this change to '.hgsub'? [Ynesfdaq?] y
301
302 warning: subrepo spec file .hgsub not found
298 abort: uncommitted changes in subrepository sub
303 abort: uncommitted changes in subrepository sub
299 [255]
304 [255]
300 % update substate when adding .hgsub w/clean updated subrepo
305 % update substate when adding .hgsub w/clean updated subrepo
@@ -304,10 +309,14 b' handle subrepos safely on qrecord'
304 new file mode 100644
309 new file mode 100644
305 examine changes to '.hgsub'? [Ynesfdaq?] y
310 examine changes to '.hgsub'? [Ynesfdaq?] y
306
311
312 @@ -0,0 +1,1 @@
313 +sub = sub
314 record this change to '.hgsub'? [Ynesfdaq?] y
315
316 warning: subrepo spec file .hgsub not found
307 path sub
317 path sub
308 source sub
318 source sub
309 revision b2fdb12cd82b021c3b7053d67802e77b6eeaee31
319 revision b2fdb12cd82b021c3b7053d67802e77b6eeaee31
310
311 $ testmod qrecord --config ui.interactive=1 -m1 1.diff <<EOF
320 $ testmod qrecord --config ui.interactive=1 -m1 1.diff <<EOF
312 > y
321 > y
313 > y
322 > y
@@ -235,7 +235,19 b' Add plain file'
235 new file mode 100644
235 new file mode 100644
236 examine changes to 'plain'? [Ynesfdaq?] y
236 examine changes to 'plain'? [Ynesfdaq?] y
237
237
238
238 @@ -0,0 +1,10 @@
239 +1
240 +2
241 +3
242 +4
243 +5
244 +6
245 +7
246 +8
247 +9
248 +10
249 record this change to 'plain'? [Ynesfdaq?] y
250
239 $ hg tip -p
251 $ hg tip -p
240 changeset: 7:11fb457c1be4
252 changeset: 7:11fb457c1be4
241 tag: tip
253 tag: tip
@@ -317,6 +329,7 b' Modify end of plain file, add EOL'
317 > y
329 > y
318 > y
330 > y
319 > y
331 > y
332 > y
320 > EOF
333 > EOF
321 diff --git a/plain b/plain
334 diff --git a/plain b/plain
322 1 hunks, 1 lines changed
335 1 hunks, 1 lines changed
@@ -335,7 +348,10 b' Modify end of plain file, add EOL'
335 new file mode 100644
348 new file mode 100644
336 examine changes to 'plain2'? [Ynesfdaq?] y
349 examine changes to 'plain2'? [Ynesfdaq?] y
337
350
338
351 @@ -0,0 +1,1 @@
352 +1
353 record change 2/2 to 'plain2'? [Ynesfdaq?] y
354
339 Modify beginning, trim end, record both, add another file to test
355 Modify beginning, trim end, record both, add another file to test
340 changes numbering
356 changes numbering
341
357
@@ -1353,6 +1369,8 b' Ignore win32text deprecation warning for'
1353 c
1369 c
1354 +d
1370 +d
1355
1371
1372
1373
1356 Test --user when ui.username not set
1374 Test --user when ui.username not set
1357 $ unset HGUSER
1375 $ unset HGUSER
1358 $ echo e >> subdir/f1
1376 $ echo e >> subdir/f1
@@ -1376,4 +1394,41 b' Test --user when ui.username not set'
1376 $ HGUSER="test"
1394 $ HGUSER="test"
1377 $ export HGUSER
1395 $ export HGUSER
1378
1396
1397
1398 Editing patch of newly added file
1399
1400 $ cat > editor.sh << '__EOF__'
1401 > cat "$1" | sed "s/first/very/g" > tt
1402 > mv tt "$1"
1403 > __EOF__
1404 $ cat > newfile << '__EOF__'
1405 > This is the first line
1406 > This is the second line
1407 > This is the third line
1408 > __EOF__
1409 $ hg add newfile
1410 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record -d '23 0' -medit-patch-new <<EOF
1411 > y
1412 > e
1413 > EOF
1414 diff --git a/newfile b/newfile
1415 new file mode 100644
1416 examine changes to 'newfile'? [Ynesfdaq?] y
1417
1418 @@ -0,0 +1,3 @@
1419 +This is the first line
1420 +This is the second line
1421 +This is the third line
1422 record this change to 'newfile'? [Ynesfdaq?] e
1423
1424 $ hg cat -r tip newfile
1425 This is the very line
1426 This is the second line
1427 This is the third line
1428
1429 $ cat newfile
1430 This is the first line
1431 This is the second line
1432 This is the third line
1433
1379 $ cd ..
1434 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now