##// END OF EJS Templates
record: checks for valid username before starting recording process (issue3456)
Sumeet -
r17446:3de04c07 default
parent child Browse files
Show More
@@ -1,666 +1,669 b''
1 1 # record.py
2 2 #
3 3 # Copyright 2007 Bryan O'Sullivan <bos@serpentine.com>
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 '''commands to interactively select changes for commit/qrefresh'''
9 9
10 10 from mercurial.i18n import gettext, _
11 11 from mercurial import cmdutil, commands, extensions, hg, mdiff, patch
12 12 from mercurial import util
13 13 import copy, cStringIO, errno, os, re, shutil, tempfile
14 14
15 15 cmdtable = {}
16 16 command = cmdutil.command(cmdtable)
17 17 testedwith = 'internal'
18 18
19 19 lines_re = re.compile(r'@@ -(\d+),(\d+) \+(\d+),(\d+) @@\s*(.*)')
20 20
21 21 diffopts = [
22 22 ('w', 'ignore-all-space', False,
23 23 _('ignore white space when comparing lines')),
24 24 ('b', 'ignore-space-change', None,
25 25 _('ignore changes in the amount of white space')),
26 26 ('B', 'ignore-blank-lines', None,
27 27 _('ignore changes whose lines are all blank')),
28 28 ]
29 29
30 30 def scanpatch(fp):
31 31 """like patch.iterhunks, but yield different events
32 32
33 33 - ('file', [header_lines + fromfile + tofile])
34 34 - ('context', [context_lines])
35 35 - ('hunk', [hunk_lines])
36 36 - ('range', (-start,len, +start,len, proc))
37 37 """
38 38 lr = patch.linereader(fp)
39 39
40 40 def scanwhile(first, p):
41 41 """scan lr while predicate holds"""
42 42 lines = [first]
43 43 while True:
44 44 line = lr.readline()
45 45 if not line:
46 46 break
47 47 if p(line):
48 48 lines.append(line)
49 49 else:
50 50 lr.push(line)
51 51 break
52 52 return lines
53 53
54 54 while True:
55 55 line = lr.readline()
56 56 if not line:
57 57 break
58 58 if line.startswith('diff --git a/') or line.startswith('diff -r '):
59 59 def notheader(line):
60 60 s = line.split(None, 1)
61 61 return not s or s[0] not in ('---', 'diff')
62 62 header = scanwhile(line, notheader)
63 63 fromfile = lr.readline()
64 64 if fromfile.startswith('---'):
65 65 tofile = lr.readline()
66 66 header += [fromfile, tofile]
67 67 else:
68 68 lr.push(fromfile)
69 69 yield 'file', header
70 70 elif line[0] == ' ':
71 71 yield 'context', scanwhile(line, lambda l: l[0] in ' \\')
72 72 elif line[0] in '-+':
73 73 yield 'hunk', scanwhile(line, lambda l: l[0] in '-+\\')
74 74 else:
75 75 m = lines_re.match(line)
76 76 if m:
77 77 yield 'range', m.groups()
78 78 else:
79 79 raise patch.PatchError('unknown patch content: %r' % line)
80 80
81 81 class header(object):
82 82 """patch header
83 83
84 84 XXX shouldn't we move this to mercurial/patch.py ?
85 85 """
86 86 diffgit_re = re.compile('diff --git a/(.*) b/(.*)$')
87 87 diff_re = re.compile('diff -r .* (.*)$')
88 88 allhunks_re = re.compile('(?:index|new file|deleted file) ')
89 89 pretty_re = re.compile('(?:new file|deleted file) ')
90 90 special_re = re.compile('(?:index|new|deleted|copy|rename) ')
91 91
92 92 def __init__(self, header):
93 93 self.header = header
94 94 self.hunks = []
95 95
96 96 def binary(self):
97 97 return util.any(h.startswith('index ') for h in self.header)
98 98
99 99 def pretty(self, fp):
100 100 for h in self.header:
101 101 if h.startswith('index '):
102 102 fp.write(_('this modifies a binary file (all or nothing)\n'))
103 103 break
104 104 if self.pretty_re.match(h):
105 105 fp.write(h)
106 106 if self.binary():
107 107 fp.write(_('this is a binary file\n'))
108 108 break
109 109 if h.startswith('---'):
110 110 fp.write(_('%d hunks, %d lines changed\n') %
111 111 (len(self.hunks),
112 112 sum([max(h.added, h.removed) for h in self.hunks])))
113 113 break
114 114 fp.write(h)
115 115
116 116 def write(self, fp):
117 117 fp.write(''.join(self.header))
118 118
119 119 def allhunks(self):
120 120 return util.any(self.allhunks_re.match(h) for h in self.header)
121 121
122 122 def files(self):
123 123 match = self.diffgit_re.match(self.header[0])
124 124 if match:
125 125 fromfile, tofile = match.groups()
126 126 if fromfile == tofile:
127 127 return [fromfile]
128 128 return [fromfile, tofile]
129 129 else:
130 130 return self.diff_re.match(self.header[0]).groups()
131 131
132 132 def filename(self):
133 133 return self.files()[-1]
134 134
135 135 def __repr__(self):
136 136 return '<header %s>' % (' '.join(map(repr, self.files())))
137 137
138 138 def special(self):
139 139 return util.any(self.special_re.match(h) for h in self.header)
140 140
141 141 def countchanges(hunk):
142 142 """hunk -> (n+,n-)"""
143 143 add = len([h for h in hunk if h[0] == '+'])
144 144 rem = len([h for h in hunk if h[0] == '-'])
145 145 return add, rem
146 146
147 147 class hunk(object):
148 148 """patch hunk
149 149
150 150 XXX shouldn't we merge this with patch.hunk ?
151 151 """
152 152 maxcontext = 3
153 153
154 154 def __init__(self, header, fromline, toline, proc, before, hunk, after):
155 155 def trimcontext(number, lines):
156 156 delta = len(lines) - self.maxcontext
157 157 if False and delta > 0:
158 158 return number + delta, lines[:self.maxcontext]
159 159 return number, lines
160 160
161 161 self.header = header
162 162 self.fromline, self.before = trimcontext(fromline, before)
163 163 self.toline, self.after = trimcontext(toline, after)
164 164 self.proc = proc
165 165 self.hunk = hunk
166 166 self.added, self.removed = countchanges(self.hunk)
167 167
168 168 def write(self, fp):
169 169 delta = len(self.before) + len(self.after)
170 170 if self.after and self.after[-1] == '\\ No newline at end of file\n':
171 171 delta -= 1
172 172 fromlen = delta + self.removed
173 173 tolen = delta + self.added
174 174 fp.write('@@ -%d,%d +%d,%d @@%s\n' %
175 175 (self.fromline, fromlen, self.toline, tolen,
176 176 self.proc and (' ' + self.proc)))
177 177 fp.write(''.join(self.before + self.hunk + self.after))
178 178
179 179 pretty = write
180 180
181 181 def filename(self):
182 182 return self.header.filename()
183 183
184 184 def __repr__(self):
185 185 return '<hunk %r@%d>' % (self.filename(), self.fromline)
186 186
187 187 def parsepatch(fp):
188 188 """patch -> [] of headers -> [] of hunks """
189 189 class parser(object):
190 190 """patch parsing state machine"""
191 191 def __init__(self):
192 192 self.fromline = 0
193 193 self.toline = 0
194 194 self.proc = ''
195 195 self.header = None
196 196 self.context = []
197 197 self.before = []
198 198 self.hunk = []
199 199 self.headers = []
200 200
201 201 def addrange(self, limits):
202 202 fromstart, fromend, tostart, toend, proc = limits
203 203 self.fromline = int(fromstart)
204 204 self.toline = int(tostart)
205 205 self.proc = proc
206 206
207 207 def addcontext(self, context):
208 208 if self.hunk:
209 209 h = hunk(self.header, self.fromline, self.toline, self.proc,
210 210 self.before, self.hunk, context)
211 211 self.header.hunks.append(h)
212 212 self.fromline += len(self.before) + h.removed
213 213 self.toline += len(self.before) + h.added
214 214 self.before = []
215 215 self.hunk = []
216 216 self.proc = ''
217 217 self.context = context
218 218
219 219 def addhunk(self, hunk):
220 220 if self.context:
221 221 self.before = self.context
222 222 self.context = []
223 223 self.hunk = hunk
224 224
225 225 def newfile(self, hdr):
226 226 self.addcontext([])
227 227 h = header(hdr)
228 228 self.headers.append(h)
229 229 self.header = h
230 230
231 231 def finished(self):
232 232 self.addcontext([])
233 233 return self.headers
234 234
235 235 transitions = {
236 236 'file': {'context': addcontext,
237 237 'file': newfile,
238 238 'hunk': addhunk,
239 239 'range': addrange},
240 240 'context': {'file': newfile,
241 241 'hunk': addhunk,
242 242 'range': addrange},
243 243 'hunk': {'context': addcontext,
244 244 'file': newfile,
245 245 'range': addrange},
246 246 'range': {'context': addcontext,
247 247 'hunk': addhunk},
248 248 }
249 249
250 250 p = parser()
251 251
252 252 state = 'context'
253 253 for newstate, data in scanpatch(fp):
254 254 try:
255 255 p.transitions[state][newstate](p, data)
256 256 except KeyError:
257 257 raise patch.PatchError('unhandled transition: %s -> %s' %
258 258 (state, newstate))
259 259 state = newstate
260 260 return p.finished()
261 261
262 262 def filterpatch(ui, headers):
263 263 """Interactively filter patch chunks into applied-only chunks"""
264 264
265 265 def prompt(skipfile, skipall, query, chunk):
266 266 """prompt query, and process base inputs
267 267
268 268 - y/n for the rest of file
269 269 - y/n for the rest
270 270 - ? (help)
271 271 - q (quit)
272 272
273 273 Return True/False and possibly updated skipfile and skipall.
274 274 """
275 275 newpatches = None
276 276 if skipall is not None:
277 277 return skipall, skipfile, skipall, newpatches
278 278 if skipfile is not None:
279 279 return skipfile, skipfile, skipall, newpatches
280 280 while True:
281 281 resps = _('[Ynesfdaq?]')
282 282 choices = (_('&Yes, record this change'),
283 283 _('&No, skip this change'),
284 284 _('&Edit the change manually'),
285 285 _('&Skip remaining changes to this file'),
286 286 _('Record remaining changes to this &file'),
287 287 _('&Done, skip remaining changes and files'),
288 288 _('Record &all changes to all remaining files'),
289 289 _('&Quit, recording no changes'),
290 290 _('&?'))
291 291 r = ui.promptchoice("%s %s" % (query, resps), choices)
292 292 ui.write("\n")
293 293 if r == 8: # ?
294 294 doc = gettext(record.__doc__)
295 295 c = doc.find('::') + 2
296 296 for l in doc[c:].splitlines():
297 297 if l.startswith(' '):
298 298 ui.write(l.strip(), '\n')
299 299 continue
300 300 elif r == 0: # yes
301 301 ret = True
302 302 elif r == 1: # no
303 303 ret = False
304 304 elif r == 2: # Edit patch
305 305 if chunk is None:
306 306 ui.write(_('cannot edit patch for whole file'))
307 307 ui.write("\n")
308 308 continue
309 309 if chunk.header.binary():
310 310 ui.write(_('cannot edit patch for binary file'))
311 311 ui.write("\n")
312 312 continue
313 313 # Patch comment based on the Git one (based on comment at end of
314 314 # http://mercurial.selenic.com/wiki/RecordExtension)
315 315 phelp = '---' + _("""
316 316 To remove '-' lines, make them ' ' lines (context).
317 317 To remove '+' lines, delete them.
318 318 Lines starting with # will be removed from the patch.
319 319
320 320 If the patch applies cleanly, the edited hunk will immediately be
321 321 added to the record list. If it does not apply cleanly, a rejects
322 322 file will be generated: you can use that when you try again. If
323 323 all lines of the hunk are removed, then the edit is aborted and
324 324 the hunk is left unchanged.
325 325 """)
326 326 (patchfd, patchfn) = tempfile.mkstemp(prefix="hg-editor-",
327 327 suffix=".diff", text=True)
328 328 ncpatchfp = None
329 329 try:
330 330 # Write the initial patch
331 331 f = os.fdopen(patchfd, "w")
332 332 chunk.header.write(f)
333 333 chunk.write(f)
334 334 f.write('\n'.join(['# ' + i for i in phelp.splitlines()]))
335 335 f.close()
336 336 # Start the editor and wait for it to complete
337 337 editor = ui.geteditor()
338 338 util.system("%s \"%s\"" % (editor, patchfn),
339 339 environ={'HGUSER': ui.username()},
340 340 onerr=util.Abort, errprefix=_("edit failed"),
341 341 out=ui.fout)
342 342 # Remove comment lines
343 343 patchfp = open(patchfn)
344 344 ncpatchfp = cStringIO.StringIO()
345 345 for line in patchfp:
346 346 if not line.startswith('#'):
347 347 ncpatchfp.write(line)
348 348 patchfp.close()
349 349 ncpatchfp.seek(0)
350 350 newpatches = parsepatch(ncpatchfp)
351 351 finally:
352 352 os.unlink(patchfn)
353 353 del ncpatchfp
354 354 # Signal that the chunk shouldn't be applied as-is, but
355 355 # provide the new patch to be used instead.
356 356 ret = False
357 357 elif r == 3: # Skip
358 358 ret = skipfile = False
359 359 elif r == 4: # file (Record remaining)
360 360 ret = skipfile = True
361 361 elif r == 5: # done, skip remaining
362 362 ret = skipall = False
363 363 elif r == 6: # all
364 364 ret = skipall = True
365 365 elif r == 7: # quit
366 366 raise util.Abort(_('user quit'))
367 367 return ret, skipfile, skipall, newpatches
368 368
369 369 seen = set()
370 370 applied = {} # 'filename' -> [] of chunks
371 371 skipfile, skipall = None, None
372 372 pos, total = 1, sum(len(h.hunks) for h in headers)
373 373 for h in headers:
374 374 pos += len(h.hunks)
375 375 skipfile = None
376 376 fixoffset = 0
377 377 hdr = ''.join(h.header)
378 378 if hdr in seen:
379 379 continue
380 380 seen.add(hdr)
381 381 if skipall is None:
382 382 h.pretty(ui)
383 383 msg = (_('examine changes to %s?') %
384 384 _(' and ').join("'%s'" % f for f in h.files()))
385 385 r, skipfile, skipall, np = prompt(skipfile, skipall, msg, None)
386 386 if not r:
387 387 continue
388 388 applied[h.filename()] = [h]
389 389 if h.allhunks():
390 390 applied[h.filename()] += h.hunks
391 391 continue
392 392 for i, chunk in enumerate(h.hunks):
393 393 if skipfile is None and skipall is None:
394 394 chunk.pretty(ui)
395 395 if total == 1:
396 396 msg = _('record this change to %r?') % chunk.filename()
397 397 else:
398 398 idx = pos - len(h.hunks) + i
399 399 msg = _('record change %d/%d to %r?') % (idx, total,
400 400 chunk.filename())
401 401 r, skipfile, skipall, newpatches = prompt(skipfile,
402 402 skipall, msg, chunk)
403 403 if r:
404 404 if fixoffset:
405 405 chunk = copy.copy(chunk)
406 406 chunk.toline += fixoffset
407 407 applied[chunk.filename()].append(chunk)
408 408 elif newpatches is not None:
409 409 for newpatch in newpatches:
410 410 for newhunk in newpatch.hunks:
411 411 if fixoffset:
412 412 newhunk.toline += fixoffset
413 413 applied[newhunk.filename()].append(newhunk)
414 414 else:
415 415 fixoffset += chunk.removed - chunk.added
416 416 return sum([h for h in applied.itervalues()
417 417 if h[0].special() or len(h) > 1], [])
418 418
419 419 @command("record",
420 420 # same options as commit + white space diff options
421 421 commands.table['^commit|ci'][1][:] + diffopts,
422 422 _('hg record [OPTION]... [FILE]...'))
423 423 def record(ui, repo, *pats, **opts):
424 424 '''interactively select changes to commit
425 425
426 426 If a list of files is omitted, all changes reported by :hg:`status`
427 427 will be candidates for recording.
428 428
429 429 See :hg:`help dates` for a list of formats valid for -d/--date.
430 430
431 431 You will be prompted for whether to record changes to each
432 432 modified file, and for files with multiple changes, for each
433 433 change to use. For each query, the following responses are
434 434 possible::
435 435
436 436 y - record this change
437 437 n - skip this change
438 438 e - edit this change manually
439 439
440 440 s - skip remaining changes to this file
441 441 f - record remaining changes to this file
442 442
443 443 d - done, skip remaining changes and files
444 444 a - record all changes to all remaining files
445 445 q - quit, recording no changes
446 446
447 447 ? - display help
448 448
449 449 This command is not available when committing a merge.'''
450 450
451 451 dorecord(ui, repo, commands.commit, 'commit', False, *pats, **opts)
452 452
453 453 def qrefresh(origfn, ui, repo, *pats, **opts):
454 454 if not opts['interactive']:
455 455 return origfn(ui, repo, *pats, **opts)
456 456
457 457 mq = extensions.find('mq')
458 458
459 459 def committomq(ui, repo, *pats, **opts):
460 460 # At this point the working copy contains only changes that
461 461 # were accepted. All other changes were reverted.
462 462 # We can't pass *pats here since qrefresh will undo all other
463 463 # changed files in the patch that aren't in pats.
464 464 mq.refresh(ui, repo, **opts)
465 465
466 466 # backup all changed files
467 467 dorecord(ui, repo, committomq, 'qrefresh', True, *pats, **opts)
468 468
469 469 def qrecord(ui, repo, patch, *pats, **opts):
470 470 '''interactively record a new patch
471 471
472 472 See :hg:`help qnew` & :hg:`help record` for more information and
473 473 usage.
474 474 '''
475 475
476 476 try:
477 477 mq = extensions.find('mq')
478 478 except KeyError:
479 479 raise util.Abort(_("'mq' extension not loaded"))
480 480
481 481 repo.mq.checkpatchname(patch)
482 482
483 483 def committomq(ui, repo, *pats, **opts):
484 484 opts['checkname'] = False
485 485 mq.new(ui, repo, patch, *pats, **opts)
486 486
487 487 dorecord(ui, repo, committomq, 'qnew', False, *pats, **opts)
488 488
489 489 def qnew(origfn, ui, repo, patch, *args, **opts):
490 490 if opts['interactive']:
491 491 return qrecord(ui, repo, patch, *args, **opts)
492 492 return origfn(ui, repo, patch, *args, **opts)
493 493
494 494 def dorecord(ui, repo, commitfunc, cmdsuggest, backupall, *pats, **opts):
495 495 if not ui.interactive():
496 496 raise util.Abort(_('running non-interactively, use %s instead') %
497 497 cmdsuggest)
498 498
499 # make sure username is set before going interactive
500 ui.username()
501
499 502 def recordfunc(ui, repo, message, match, opts):
500 503 """This is generic record driver.
501 504
502 505 Its job is to interactively filter local changes, and
503 506 accordingly prepare working directory into a state in which the
504 507 job can be delegated to a non-interactive commit command such as
505 508 'commit' or 'qrefresh'.
506 509
507 510 After the actual job is done by non-interactive command, the
508 511 working directory is restored to its original state.
509 512
510 513 In the end we'll record interesting changes, and everything else
511 514 will be left in place, so the user can continue working.
512 515 """
513 516
514 517 merge = len(repo[None].parents()) > 1
515 518 if merge:
516 519 raise util.Abort(_('cannot partially commit a merge '
517 520 '(use "hg commit" instead)'))
518 521
519 522 changes = repo.status(match=match)[:3]
520 523 diffopts = mdiff.diffopts(
521 524 git=True, nodates=True,
522 525 ignorews=opts.get('ignore_all_space'),
523 526 ignorewsamount=opts.get('ignore_space_change'),
524 527 ignoreblanklines=opts.get('ignore_blank_lines'))
525 528 chunks = patch.diff(repo, changes=changes, opts=diffopts)
526 529 fp = cStringIO.StringIO()
527 530 fp.write(''.join(chunks))
528 531 fp.seek(0)
529 532
530 533 # 1. filter patch, so we have intending-to apply subset of it
531 534 chunks = filterpatch(ui, parsepatch(fp))
532 535 del fp
533 536
534 537 contenders = set()
535 538 for h in chunks:
536 539 try:
537 540 contenders.update(set(h.files()))
538 541 except AttributeError:
539 542 pass
540 543
541 544 changed = changes[0] + changes[1] + changes[2]
542 545 newfiles = [f for f in changed if f in contenders]
543 546 if not newfiles:
544 547 ui.status(_('no changes to record\n'))
545 548 return 0
546 549
547 550 modified = set(changes[0])
548 551
549 552 # 2. backup changed files, so we can restore them in the end
550 553 if backupall:
551 554 tobackup = changed
552 555 else:
553 556 tobackup = [f for f in newfiles if f in modified]
554 557
555 558 backups = {}
556 559 if tobackup:
557 560 backupdir = repo.join('record-backups')
558 561 try:
559 562 os.mkdir(backupdir)
560 563 except OSError, err:
561 564 if err.errno != errno.EEXIST:
562 565 raise
563 566 try:
564 567 # backup continues
565 568 for f in tobackup:
566 569 fd, tmpname = tempfile.mkstemp(prefix=f.replace('/', '_')+'.',
567 570 dir=backupdir)
568 571 os.close(fd)
569 572 ui.debug('backup %r as %r\n' % (f, tmpname))
570 573 util.copyfile(repo.wjoin(f), tmpname)
571 574 shutil.copystat(repo.wjoin(f), tmpname)
572 575 backups[f] = tmpname
573 576
574 577 fp = cStringIO.StringIO()
575 578 for c in chunks:
576 579 if c.filename() in backups:
577 580 c.write(fp)
578 581 dopatch = fp.tell()
579 582 fp.seek(0)
580 583
581 584 # 3a. apply filtered patch to clean repo (clean)
582 585 if backups:
583 586 hg.revert(repo, repo.dirstate.p1(),
584 587 lambda key: key in backups)
585 588
586 589 # 3b. (apply)
587 590 if dopatch:
588 591 try:
589 592 ui.debug('applying patch\n')
590 593 ui.debug(fp.getvalue())
591 594 patch.internalpatch(ui, repo, fp, 1, eolmode=None)
592 595 except patch.PatchError, err:
593 596 raise util.Abort(str(err))
594 597 del fp
595 598
596 599 # 4. We prepared working directory according to filtered
597 600 # patch. Now is the time to delegate the job to
598 601 # commit/qrefresh or the like!
599 602
600 603 # it is important to first chdir to repo root -- we'll call
601 604 # a highlevel command with list of pathnames relative to
602 605 # repo root
603 606 cwd = os.getcwd()
604 607 os.chdir(repo.root)
605 608 try:
606 609 commitfunc(ui, repo, *newfiles, **opts)
607 610 finally:
608 611 os.chdir(cwd)
609 612
610 613 return 0
611 614 finally:
612 615 # 5. finally restore backed-up files
613 616 try:
614 617 for realname, tmpname in backups.iteritems():
615 618 ui.debug('restoring %r to %r\n' % (tmpname, realname))
616 619 util.copyfile(tmpname, repo.wjoin(realname))
617 620 # Our calls to copystat() here and above are a
618 621 # hack to trick any editors that have f open that
619 622 # we haven't modified them.
620 623 #
621 624 # Also note that this racy as an editor could
622 625 # notice the file's mtime before we've finished
623 626 # writing it.
624 627 shutil.copystat(tmpname, repo.wjoin(realname))
625 628 os.unlink(tmpname)
626 629 if tobackup:
627 630 os.rmdir(backupdir)
628 631 except OSError:
629 632 pass
630 633
631 634 # wrap ui.write so diff output can be labeled/colorized
632 635 def wrapwrite(orig, *args, **kw):
633 636 label = kw.pop('label', '')
634 637 for chunk, l in patch.difflabel(lambda: args):
635 638 orig(chunk, label=label + l)
636 639 oldwrite = ui.write
637 640 extensions.wrapfunction(ui, 'write', wrapwrite)
638 641 try:
639 642 return cmdutil.commit(ui, repo, recordfunc, pats, opts)
640 643 finally:
641 644 ui.write = oldwrite
642 645
643 646 cmdtable["qrecord"] = \
644 647 (qrecord, [], # placeholder until mq is available
645 648 _('hg qrecord [OPTION]... PATCH [FILE]...'))
646 649
647 650 def uisetup(ui):
648 651 try:
649 652 mq = extensions.find('mq')
650 653 except KeyError:
651 654 return
652 655
653 656 cmdtable["qrecord"] = \
654 657 (qrecord,
655 658 # same options as qnew, but copy them so we don't get
656 659 # -i/--interactive for qrecord and add white space diff options
657 660 mq.cmdtable['^qnew'][1][:] + diffopts,
658 661 _('hg qrecord [OPTION]... PATCH [FILE]...'))
659 662
660 663 _wrapcmd('qnew', mq.cmdtable, qnew, _("interactively record a new patch"))
661 664 _wrapcmd('qrefresh', mq.cmdtable, qrefresh,
662 665 _("interactively select changes to refresh"))
663 666
664 667 def _wrapcmd(cmd, table, wrapfn, msg):
665 668 entry = extensions.wrapcommand(table, cmd, wrapfn)
666 669 entry[1].append(('i', 'interactive', None, msg))
@@ -1,1221 +1,1230 b''
1 1 Set up a repo
2 2
3 3 $ echo "[ui]" >> $HGRCPATH
4 4 $ echo "interactive=true" >> $HGRCPATH
5 5 $ echo "[extensions]" >> $HGRCPATH
6 6 $ echo "record=" >> $HGRCPATH
7 7
8 8 $ hg init a
9 9 $ cd a
10 10
11 11 Select no files
12 12
13 13 $ touch empty-rw
14 14 $ hg add empty-rw
15 15
16 16 $ hg record empty-rw<<EOF
17 17 > n
18 18 > EOF
19 19 diff --git a/empty-rw b/empty-rw
20 20 new file mode 100644
21 21 examine changes to 'empty-rw'? [Ynesfdaq?]
22 22 no changes to record
23 23
24 24 $ hg tip -p
25 25 changeset: -1:000000000000
26 26 tag: tip
27 27 user:
28 28 date: Thu Jan 01 00:00:00 1970 +0000
29 29
30 30
31 31
32 32 Select files but no hunks
33 33
34 34 $ hg record empty-rw<<EOF
35 35 > y
36 36 > n
37 37 > EOF
38 38 diff --git a/empty-rw b/empty-rw
39 39 new file mode 100644
40 40 examine changes to 'empty-rw'? [Ynesfdaq?]
41 41 abort: empty commit message
42 42 [255]
43 43
44 44 $ hg tip -p
45 45 changeset: -1:000000000000
46 46 tag: tip
47 47 user:
48 48 date: Thu Jan 01 00:00:00 1970 +0000
49 49
50 50
51 51
52 52 Record empty file
53 53
54 54 $ hg record -d '0 0' -m empty empty-rw<<EOF
55 55 > y
56 56 > y
57 57 > EOF
58 58 diff --git a/empty-rw b/empty-rw
59 59 new file mode 100644
60 60 examine changes to 'empty-rw'? [Ynesfdaq?]
61 61
62 62 $ hg tip -p
63 63 changeset: 0:c0708cf4e46e
64 64 tag: tip
65 65 user: test
66 66 date: Thu Jan 01 00:00:00 1970 +0000
67 67 summary: empty
68 68
69 69
70 70
71 71 Summary shows we updated to the new cset
72 72
73 73 $ hg summary
74 74 parent: 0:c0708cf4e46e tip
75 75 empty
76 76 branch: default
77 77 commit: (clean)
78 78 update: (current)
79 79
80 80 Rename empty file
81 81
82 82 $ hg mv empty-rw empty-rename
83 83 $ hg record -d '1 0' -m rename<<EOF
84 84 > y
85 85 > EOF
86 86 diff --git a/empty-rw b/empty-rename
87 87 rename from empty-rw
88 88 rename to empty-rename
89 89 examine changes to 'empty-rw' and 'empty-rename'? [Ynesfdaq?]
90 90
91 91 $ hg tip -p
92 92 changeset: 1:d695e8dcb197
93 93 tag: tip
94 94 user: test
95 95 date: Thu Jan 01 00:00:01 1970 +0000
96 96 summary: rename
97 97
98 98
99 99
100 100 Copy empty file
101 101
102 102 $ hg cp empty-rename empty-copy
103 103 $ hg record -d '2 0' -m copy<<EOF
104 104 > y
105 105 > EOF
106 106 diff --git a/empty-rename b/empty-copy
107 107 copy from empty-rename
108 108 copy to empty-copy
109 109 examine changes to 'empty-rename' and 'empty-copy'? [Ynesfdaq?]
110 110
111 111 $ hg tip -p
112 112 changeset: 2:1d4b90bea524
113 113 tag: tip
114 114 user: test
115 115 date: Thu Jan 01 00:00:02 1970 +0000
116 116 summary: copy
117 117
118 118
119 119
120 120 Delete empty file
121 121
122 122 $ hg rm empty-copy
123 123 $ hg record -d '3 0' -m delete<<EOF
124 124 > y
125 125 > EOF
126 126 diff --git a/empty-copy b/empty-copy
127 127 deleted file mode 100644
128 128 examine changes to 'empty-copy'? [Ynesfdaq?]
129 129
130 130 $ hg tip -p
131 131 changeset: 3:b39a238f01a1
132 132 tag: tip
133 133 user: test
134 134 date: Thu Jan 01 00:00:03 1970 +0000
135 135 summary: delete
136 136
137 137
138 138
139 139 Add binary file
140 140
141 141 $ hg bundle --base -2 tip.bundle
142 142 1 changesets found
143 143 $ hg add tip.bundle
144 144 $ hg record -d '4 0' -m binary<<EOF
145 145 > y
146 146 > EOF
147 147 diff --git a/tip.bundle b/tip.bundle
148 148 new file mode 100644
149 149 this is a binary file
150 150 examine changes to 'tip.bundle'? [Ynesfdaq?]
151 151
152 152 $ hg tip -p
153 153 changeset: 4:ad816da3711e
154 154 tag: tip
155 155 user: test
156 156 date: Thu Jan 01 00:00:04 1970 +0000
157 157 summary: binary
158 158
159 159 diff -r b39a238f01a1 -r ad816da3711e tip.bundle
160 160 Binary file tip.bundle has changed
161 161
162 162
163 163 Change binary file
164 164
165 165 $ hg bundle --base -2 tip.bundle
166 166 1 changesets found
167 167 $ hg record -d '5 0' -m binary-change<<EOF
168 168 > y
169 169 > EOF
170 170 diff --git a/tip.bundle b/tip.bundle
171 171 this modifies a binary file (all or nothing)
172 172 examine changes to 'tip.bundle'? [Ynesfdaq?]
173 173
174 174 $ hg tip -p
175 175 changeset: 5:dccd6f3eb485
176 176 tag: tip
177 177 user: test
178 178 date: Thu Jan 01 00:00:05 1970 +0000
179 179 summary: binary-change
180 180
181 181 diff -r ad816da3711e -r dccd6f3eb485 tip.bundle
182 182 Binary file tip.bundle has changed
183 183
184 184
185 185 Rename and change binary file
186 186
187 187 $ hg mv tip.bundle top.bundle
188 188 $ hg bundle --base -2 top.bundle
189 189 1 changesets found
190 190 $ hg record -d '6 0' -m binary-change-rename<<EOF
191 191 > y
192 192 > EOF
193 193 diff --git a/tip.bundle b/top.bundle
194 194 rename from tip.bundle
195 195 rename to top.bundle
196 196 this modifies a binary file (all or nothing)
197 197 examine changes to 'tip.bundle' and 'top.bundle'? [Ynesfdaq?]
198 198
199 199 $ hg tip -p
200 200 changeset: 6:7fa44105f5b3
201 201 tag: tip
202 202 user: test
203 203 date: Thu Jan 01 00:00:06 1970 +0000
204 204 summary: binary-change-rename
205 205
206 206 diff -r dccd6f3eb485 -r 7fa44105f5b3 tip.bundle
207 207 Binary file tip.bundle has changed
208 208 diff -r dccd6f3eb485 -r 7fa44105f5b3 top.bundle
209 209 Binary file top.bundle has changed
210 210
211 211
212 212 Add plain file
213 213
214 214 $ for i in 1 2 3 4 5 6 7 8 9 10; do
215 215 > echo $i >> plain
216 216 > done
217 217
218 218 $ hg add plain
219 219 $ hg record -d '7 0' -m plain plain<<EOF
220 220 > y
221 221 > y
222 222 > EOF
223 223 diff --git a/plain b/plain
224 224 new file mode 100644
225 225 examine changes to 'plain'? [Ynesfdaq?]
226 226
227 227 $ hg tip -p
228 228 changeset: 7:11fb457c1be4
229 229 tag: tip
230 230 user: test
231 231 date: Thu Jan 01 00:00:07 1970 +0000
232 232 summary: plain
233 233
234 234 diff -r 7fa44105f5b3 -r 11fb457c1be4 plain
235 235 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
236 236 +++ b/plain Thu Jan 01 00:00:07 1970 +0000
237 237 @@ -0,0 +1,10 @@
238 238 +1
239 239 +2
240 240 +3
241 241 +4
242 242 +5
243 243 +6
244 244 +7
245 245 +8
246 246 +9
247 247 +10
248 248
249 Modify end of plain file with username unset
250
251 $ echo 11 >> plain
252 $ unset HGUSER
253 $ hg record --config ui.username= -d '8 0' -m end plain
254 abort: no username supplied (see "hg help config")
255 [255]
256
249 257
250 258 Modify end of plain file
251 259
252 $ echo 11 >> plain
260 $ HGUSER="test"
261 $ export HGUSER
253 262 $ hg record -d '8 0' -m end plain <<EOF
254 263 > y
255 264 > y
256 265 > EOF
257 266 diff --git a/plain b/plain
258 267 1 hunks, 1 lines changed
259 268 examine changes to 'plain'? [Ynesfdaq?]
260 269 @@ -8,3 +8,4 @@
261 270 8
262 271 9
263 272 10
264 273 +11
265 274 record this change to 'plain'? [Ynesfdaq?]
266 275
267 276 Modify end of plain file, no EOL
268 277
269 278 $ hg tip --template '{node}' >> plain
270 279 $ hg record -d '9 0' -m noeol plain <<EOF
271 280 > y
272 281 > y
273 282 > EOF
274 283 diff --git a/plain b/plain
275 284 1 hunks, 1 lines changed
276 285 examine changes to 'plain'? [Ynesfdaq?]
277 286 @@ -9,3 +9,4 @@
278 287 9
279 288 10
280 289 11
281 290 +7264f99c5f5ff3261504828afa4fb4d406c3af54
282 291 \ No newline at end of file
283 292 record this change to 'plain'? [Ynesfdaq?]
284 293
285 294 Modify end of plain file, add EOL
286 295
287 296 $ echo >> plain
288 297 $ echo 1 > plain2
289 298 $ hg add plain2
290 299 $ hg record -d '10 0' -m eol plain plain2 <<EOF
291 300 > y
292 301 > y
293 302 > y
294 303 > EOF
295 304 diff --git a/plain b/plain
296 305 1 hunks, 1 lines changed
297 306 examine changes to 'plain'? [Ynesfdaq?]
298 307 @@ -9,4 +9,4 @@
299 308 9
300 309 10
301 310 11
302 311 -7264f99c5f5ff3261504828afa4fb4d406c3af54
303 312 \ No newline at end of file
304 313 +7264f99c5f5ff3261504828afa4fb4d406c3af54
305 314 record change 1/2 to 'plain'? [Ynesfdaq?]
306 315 diff --git a/plain2 b/plain2
307 316 new file mode 100644
308 317 examine changes to 'plain2'? [Ynesfdaq?]
309 318
310 319 Modify beginning, trim end, record both, add another file to test
311 320 changes numbering
312 321
313 322 $ rm plain
314 323 $ for i in 2 2 3 4 5 6 7 8 9 10; do
315 324 > echo $i >> plain
316 325 > done
317 326 $ echo 2 >> plain2
318 327
319 328 $ hg record -d '10 0' -m begin-and-end plain plain2 <<EOF
320 329 > y
321 330 > y
322 331 > y
323 332 > y
324 333 > y
325 334 > EOF
326 335 diff --git a/plain b/plain
327 336 2 hunks, 3 lines changed
328 337 examine changes to 'plain'? [Ynesfdaq?]
329 338 @@ -1,4 +1,4 @@
330 339 -1
331 340 +2
332 341 2
333 342 3
334 343 4
335 344 record change 1/3 to 'plain'? [Ynesfdaq?]
336 345 @@ -8,5 +8,3 @@
337 346 8
338 347 9
339 348 10
340 349 -11
341 350 -7264f99c5f5ff3261504828afa4fb4d406c3af54
342 351 record change 2/3 to 'plain'? [Ynesfdaq?]
343 352 diff --git a/plain2 b/plain2
344 353 1 hunks, 1 lines changed
345 354 examine changes to 'plain2'? [Ynesfdaq?]
346 355 @@ -1,1 +1,2 @@
347 356 1
348 357 +2
349 358 record change 3/3 to 'plain2'? [Ynesfdaq?]
350 359
351 360 $ hg tip -p
352 361 changeset: 11:21df83db12b8
353 362 tag: tip
354 363 user: test
355 364 date: Thu Jan 01 00:00:10 1970 +0000
356 365 summary: begin-and-end
357 366
358 367 diff -r ddb8b281c3ff -r 21df83db12b8 plain
359 368 --- a/plain Thu Jan 01 00:00:10 1970 +0000
360 369 +++ b/plain Thu Jan 01 00:00:10 1970 +0000
361 370 @@ -1,4 +1,4 @@
362 371 -1
363 372 +2
364 373 2
365 374 3
366 375 4
367 376 @@ -8,5 +8,3 @@
368 377 8
369 378 9
370 379 10
371 380 -11
372 381 -7264f99c5f5ff3261504828afa4fb4d406c3af54
373 382 diff -r ddb8b281c3ff -r 21df83db12b8 plain2
374 383 --- a/plain2 Thu Jan 01 00:00:10 1970 +0000
375 384 +++ b/plain2 Thu Jan 01 00:00:10 1970 +0000
376 385 @@ -1,1 +1,2 @@
377 386 1
378 387 +2
379 388
380 389
381 390 Trim beginning, modify end
382 391
383 392 $ rm plain
384 393 > for i in 4 5 6 7 8 9 10.new; do
385 394 > echo $i >> plain
386 395 > done
387 396
388 397 Record end
389 398
390 399 $ hg record -d '11 0' -m end-only plain <<EOF
391 400 > y
392 401 > n
393 402 > y
394 403 > EOF
395 404 diff --git a/plain b/plain
396 405 2 hunks, 4 lines changed
397 406 examine changes to 'plain'? [Ynesfdaq?]
398 407 @@ -1,9 +1,6 @@
399 408 -2
400 409 -2
401 410 -3
402 411 4
403 412 5
404 413 6
405 414 7
406 415 8
407 416 9
408 417 record change 1/2 to 'plain'? [Ynesfdaq?]
409 418 @@ -4,7 +1,7 @@
410 419 4
411 420 5
412 421 6
413 422 7
414 423 8
415 424 9
416 425 -10
417 426 +10.new
418 427 record change 2/2 to 'plain'? [Ynesfdaq?]
419 428
420 429 $ hg tip -p
421 430 changeset: 12:99337501826f
422 431 tag: tip
423 432 user: test
424 433 date: Thu Jan 01 00:00:11 1970 +0000
425 434 summary: end-only
426 435
427 436 diff -r 21df83db12b8 -r 99337501826f plain
428 437 --- a/plain Thu Jan 01 00:00:10 1970 +0000
429 438 +++ b/plain Thu Jan 01 00:00:11 1970 +0000
430 439 @@ -7,4 +7,4 @@
431 440 7
432 441 8
433 442 9
434 443 -10
435 444 +10.new
436 445
437 446
438 447 Record beginning
439 448
440 449 $ hg record -d '12 0' -m begin-only plain <<EOF
441 450 > y
442 451 > y
443 452 > EOF
444 453 diff --git a/plain b/plain
445 454 1 hunks, 3 lines changed
446 455 examine changes to 'plain'? [Ynesfdaq?]
447 456 @@ -1,6 +1,3 @@
448 457 -2
449 458 -2
450 459 -3
451 460 4
452 461 5
453 462 6
454 463 record this change to 'plain'? [Ynesfdaq?]
455 464
456 465 $ hg tip -p
457 466 changeset: 13:bbd45465d540
458 467 tag: tip
459 468 user: test
460 469 date: Thu Jan 01 00:00:12 1970 +0000
461 470 summary: begin-only
462 471
463 472 diff -r 99337501826f -r bbd45465d540 plain
464 473 --- a/plain Thu Jan 01 00:00:11 1970 +0000
465 474 +++ b/plain Thu Jan 01 00:00:12 1970 +0000
466 475 @@ -1,6 +1,3 @@
467 476 -2
468 477 -2
469 478 -3
470 479 4
471 480 5
472 481 6
473 482
474 483
475 484 Add to beginning, trim from end
476 485
477 486 $ rm plain
478 487 $ for i in 1 2 3 4 5 6 7 8 9; do
479 488 > echo $i >> plain
480 489 > done
481 490
482 491 Record end
483 492
484 493 $ hg record --traceback -d '13 0' -m end-again plain<<EOF
485 494 > y
486 495 > n
487 496 > y
488 497 > EOF
489 498 diff --git a/plain b/plain
490 499 2 hunks, 4 lines changed
491 500 examine changes to 'plain'? [Ynesfdaq?]
492 501 @@ -1,6 +1,9 @@
493 502 +1
494 503 +2
495 504 +3
496 505 4
497 506 5
498 507 6
499 508 7
500 509 8
501 510 9
502 511 record change 1/2 to 'plain'? [Ynesfdaq?]
503 512 @@ -1,7 +4,6 @@
504 513 4
505 514 5
506 515 6
507 516 7
508 517 8
509 518 9
510 519 -10.new
511 520 record change 2/2 to 'plain'? [Ynesfdaq?]
512 521
513 522 Add to beginning, middle, end
514 523
515 524 $ rm plain
516 525 $ for i in 1 2 3 4 5 5.new 5.reallynew 6 7 8 9 10 11; do
517 526 > echo $i >> plain
518 527 > done
519 528
520 529 Record beginning, middle
521 530
522 531 $ hg record -d '14 0' -m middle-only plain <<EOF
523 532 > y
524 533 > y
525 534 > y
526 535 > n
527 536 > EOF
528 537 diff --git a/plain b/plain
529 538 3 hunks, 7 lines changed
530 539 examine changes to 'plain'? [Ynesfdaq?]
531 540 @@ -1,2 +1,5 @@
532 541 +1
533 542 +2
534 543 +3
535 544 4
536 545 5
537 546 record change 1/3 to 'plain'? [Ynesfdaq?]
538 547 @@ -1,6 +4,8 @@
539 548 4
540 549 5
541 550 +5.new
542 551 +5.reallynew
543 552 6
544 553 7
545 554 8
546 555 9
547 556 record change 2/3 to 'plain'? [Ynesfdaq?]
548 557 @@ -3,4 +8,6 @@
549 558 6
550 559 7
551 560 8
552 561 9
553 562 +10
554 563 +11
555 564 record change 3/3 to 'plain'? [Ynesfdaq?]
556 565
557 566 $ hg tip -p
558 567 changeset: 15:f34a7937ec33
559 568 tag: tip
560 569 user: test
561 570 date: Thu Jan 01 00:00:14 1970 +0000
562 571 summary: middle-only
563 572
564 573 diff -r 82c065d0b850 -r f34a7937ec33 plain
565 574 --- a/plain Thu Jan 01 00:00:13 1970 +0000
566 575 +++ b/plain Thu Jan 01 00:00:14 1970 +0000
567 576 @@ -1,5 +1,10 @@
568 577 +1
569 578 +2
570 579 +3
571 580 4
572 581 5
573 582 +5.new
574 583 +5.reallynew
575 584 6
576 585 7
577 586 8
578 587
579 588
580 589 Record end
581 590
582 591 $ hg record -d '15 0' -m end-only plain <<EOF
583 592 > y
584 593 > y
585 594 > EOF
586 595 diff --git a/plain b/plain
587 596 1 hunks, 2 lines changed
588 597 examine changes to 'plain'? [Ynesfdaq?]
589 598 @@ -9,3 +9,5 @@
590 599 7
591 600 8
592 601 9
593 602 +10
594 603 +11
595 604 record this change to 'plain'? [Ynesfdaq?]
596 605
597 606 $ hg tip -p
598 607 changeset: 16:f9900b71a04c
599 608 tag: tip
600 609 user: test
601 610 date: Thu Jan 01 00:00:15 1970 +0000
602 611 summary: end-only
603 612
604 613 diff -r f34a7937ec33 -r f9900b71a04c plain
605 614 --- a/plain Thu Jan 01 00:00:14 1970 +0000
606 615 +++ b/plain Thu Jan 01 00:00:15 1970 +0000
607 616 @@ -9,3 +9,5 @@
608 617 7
609 618 8
610 619 9
611 620 +10
612 621 +11
613 622
614 623
615 624 $ mkdir subdir
616 625 $ cd subdir
617 626 $ echo a > a
618 627 $ hg ci -d '16 0' -Amsubdir
619 628 adding subdir/a
620 629
621 630 $ echo a >> a
622 631 $ hg record -d '16 0' -m subdir-change a <<EOF
623 632 > y
624 633 > y
625 634 > EOF
626 635 diff --git a/subdir/a b/subdir/a
627 636 1 hunks, 1 lines changed
628 637 examine changes to 'subdir/a'? [Ynesfdaq?]
629 638 @@ -1,1 +1,2 @@
630 639 a
631 640 +a
632 641 record this change to 'subdir/a'? [Ynesfdaq?]
633 642
634 643 $ hg tip -p
635 644 changeset: 18:61be427a9deb
636 645 tag: tip
637 646 user: test
638 647 date: Thu Jan 01 00:00:16 1970 +0000
639 648 summary: subdir-change
640 649
641 650 diff -r a7ffae4d61cb -r 61be427a9deb subdir/a
642 651 --- a/subdir/a Thu Jan 01 00:00:16 1970 +0000
643 652 +++ b/subdir/a Thu Jan 01 00:00:16 1970 +0000
644 653 @@ -1,1 +1,2 @@
645 654 a
646 655 +a
647 656
648 657
649 658 $ echo a > f1
650 659 $ echo b > f2
651 660 $ hg add f1 f2
652 661
653 662 $ hg ci -mz -d '17 0'
654 663
655 664 $ echo a >> f1
656 665 $ echo b >> f2
657 666
658 667 Help, quit
659 668
660 669 $ hg record <<EOF
661 670 > ?
662 671 > q
663 672 > EOF
664 673 diff --git a/subdir/f1 b/subdir/f1
665 674 1 hunks, 1 lines changed
666 675 examine changes to 'subdir/f1'? [Ynesfdaq?]
667 676 y - record this change
668 677 n - skip this change
669 678 e - edit this change manually
670 679 s - skip remaining changes to this file
671 680 f - record remaining changes to this file
672 681 d - done, skip remaining changes and files
673 682 a - record all changes to all remaining files
674 683 q - quit, recording no changes
675 684 ? - display help
676 685 examine changes to 'subdir/f1'? [Ynesfdaq?]
677 686 abort: user quit
678 687 [255]
679 688
680 689 Skip
681 690
682 691 $ hg record <<EOF
683 692 > s
684 693 > EOF
685 694 diff --git a/subdir/f1 b/subdir/f1
686 695 1 hunks, 1 lines changed
687 696 examine changes to 'subdir/f1'? [Ynesfdaq?]
688 697 diff --git a/subdir/f2 b/subdir/f2
689 698 1 hunks, 1 lines changed
690 699 examine changes to 'subdir/f2'? [Ynesfdaq?] abort: response expected
691 700 [255]
692 701
693 702 No
694 703
695 704 $ hg record <<EOF
696 705 > n
697 706 > EOF
698 707 diff --git a/subdir/f1 b/subdir/f1
699 708 1 hunks, 1 lines changed
700 709 examine changes to 'subdir/f1'? [Ynesfdaq?]
701 710 diff --git a/subdir/f2 b/subdir/f2
702 711 1 hunks, 1 lines changed
703 712 examine changes to 'subdir/f2'? [Ynesfdaq?] abort: response expected
704 713 [255]
705 714
706 715 f, quit
707 716
708 717 $ hg record <<EOF
709 718 > f
710 719 > q
711 720 > EOF
712 721 diff --git a/subdir/f1 b/subdir/f1
713 722 1 hunks, 1 lines changed
714 723 examine changes to 'subdir/f1'? [Ynesfdaq?]
715 724 diff --git a/subdir/f2 b/subdir/f2
716 725 1 hunks, 1 lines changed
717 726 examine changes to 'subdir/f2'? [Ynesfdaq?]
718 727 abort: user quit
719 728 [255]
720 729
721 730 s, all
722 731
723 732 $ hg record -d '18 0' -mx <<EOF
724 733 > s
725 734 > a
726 735 > EOF
727 736 diff --git a/subdir/f1 b/subdir/f1
728 737 1 hunks, 1 lines changed
729 738 examine changes to 'subdir/f1'? [Ynesfdaq?]
730 739 diff --git a/subdir/f2 b/subdir/f2
731 740 1 hunks, 1 lines changed
732 741 examine changes to 'subdir/f2'? [Ynesfdaq?]
733 742
734 743 $ hg tip -p
735 744 changeset: 20:b3df3dda369a
736 745 tag: tip
737 746 user: test
738 747 date: Thu Jan 01 00:00:18 1970 +0000
739 748 summary: x
740 749
741 750 diff -r 6e02d6c9906d -r b3df3dda369a subdir/f2
742 751 --- a/subdir/f2 Thu Jan 01 00:00:17 1970 +0000
743 752 +++ b/subdir/f2 Thu Jan 01 00:00:18 1970 +0000
744 753 @@ -1,1 +1,2 @@
745 754 b
746 755 +b
747 756
748 757
749 758 f
750 759
751 760 $ hg record -d '19 0' -my <<EOF
752 761 > f
753 762 > EOF
754 763 diff --git a/subdir/f1 b/subdir/f1
755 764 1 hunks, 1 lines changed
756 765 examine changes to 'subdir/f1'? [Ynesfdaq?]
757 766
758 767 $ hg tip -p
759 768 changeset: 21:38ec577f126b
760 769 tag: tip
761 770 user: test
762 771 date: Thu Jan 01 00:00:19 1970 +0000
763 772 summary: y
764 773
765 774 diff -r b3df3dda369a -r 38ec577f126b subdir/f1
766 775 --- a/subdir/f1 Thu Jan 01 00:00:18 1970 +0000
767 776 +++ b/subdir/f1 Thu Jan 01 00:00:19 1970 +0000
768 777 @@ -1,1 +1,2 @@
769 778 a
770 779 +a
771 780
772 781
773 782 #if execbit
774 783
775 784 Preserve chmod +x
776 785
777 786 $ chmod +x f1
778 787 $ echo a >> f1
779 788 $ hg record -d '20 0' -mz <<EOF
780 789 > y
781 790 > y
782 791 > y
783 792 > EOF
784 793 diff --git a/subdir/f1 b/subdir/f1
785 794 old mode 100644
786 795 new mode 100755
787 796 1 hunks, 1 lines changed
788 797 examine changes to 'subdir/f1'? [Ynesfdaq?]
789 798 @@ -1,2 +1,3 @@
790 799 a
791 800 a
792 801 +a
793 802 record this change to 'subdir/f1'? [Ynesfdaq?]
794 803
795 804 $ hg tip --config diff.git=True -p
796 805 changeset: 22:3261adceb075
797 806 tag: tip
798 807 user: test
799 808 date: Thu Jan 01 00:00:20 1970 +0000
800 809 summary: z
801 810
802 811 diff --git a/subdir/f1 b/subdir/f1
803 812 old mode 100644
804 813 new mode 100755
805 814 --- a/subdir/f1
806 815 +++ b/subdir/f1
807 816 @@ -1,2 +1,3 @@
808 817 a
809 818 a
810 819 +a
811 820
812 821
813 822 Preserve execute permission on original
814 823
815 824 $ echo b >> f1
816 825 $ hg record -d '21 0' -maa <<EOF
817 826 > y
818 827 > y
819 828 > y
820 829 > EOF
821 830 diff --git a/subdir/f1 b/subdir/f1
822 831 1 hunks, 1 lines changed
823 832 examine changes to 'subdir/f1'? [Ynesfdaq?]
824 833 @@ -1,3 +1,4 @@
825 834 a
826 835 a
827 836 a
828 837 +b
829 838 record this change to 'subdir/f1'? [Ynesfdaq?]
830 839
831 840 $ hg tip --config diff.git=True -p
832 841 changeset: 23:b429867550db
833 842 tag: tip
834 843 user: test
835 844 date: Thu Jan 01 00:00:21 1970 +0000
836 845 summary: aa
837 846
838 847 diff --git a/subdir/f1 b/subdir/f1
839 848 --- a/subdir/f1
840 849 +++ b/subdir/f1
841 850 @@ -1,3 +1,4 @@
842 851 a
843 852 a
844 853 a
845 854 +b
846 855
847 856
848 857 Preserve chmod -x
849 858
850 859 $ chmod -x f1
851 860 $ echo c >> f1
852 861 $ hg record -d '22 0' -mab <<EOF
853 862 > y
854 863 > y
855 864 > y
856 865 > EOF
857 866 diff --git a/subdir/f1 b/subdir/f1
858 867 old mode 100755
859 868 new mode 100644
860 869 1 hunks, 1 lines changed
861 870 examine changes to 'subdir/f1'? [Ynesfdaq?]
862 871 @@ -2,3 +2,4 @@
863 872 a
864 873 a
865 874 b
866 875 +c
867 876 record this change to 'subdir/f1'? [Ynesfdaq?]
868 877
869 878 $ hg tip --config diff.git=True -p
870 879 changeset: 24:0b082130c20a
871 880 tag: tip
872 881 user: test
873 882 date: Thu Jan 01 00:00:22 1970 +0000
874 883 summary: ab
875 884
876 885 diff --git a/subdir/f1 b/subdir/f1
877 886 old mode 100755
878 887 new mode 100644
879 888 --- a/subdir/f1
880 889 +++ b/subdir/f1
881 890 @@ -2,3 +2,4 @@
882 891 a
883 892 a
884 893 b
885 894 +c
886 895
887 896
888 897 #else
889 898
890 899 Slightly bogus tests to get almost same repo structure as when x bit is used
891 900 - but with different hashes.
892 901
893 902 Mock "Preserve chmod +x"
894 903
895 904 $ echo a >> f1
896 905 $ hg record -d '20 0' -mz <<EOF
897 906 > y
898 907 > y
899 908 > y
900 909 > EOF
901 910 diff --git a/subdir/f1 b/subdir/f1
902 911 1 hunks, 1 lines changed
903 912 examine changes to 'subdir/f1'? [Ynesfdaq?]
904 913 @@ -1,2 +1,3 @@
905 914 a
906 915 a
907 916 +a
908 917 record this change to 'subdir/f1'? [Ynesfdaq?]
909 918
910 919 $ hg tip --config diff.git=True -p
911 920 changeset: 22:0d463bd428f5
912 921 tag: tip
913 922 user: test
914 923 date: Thu Jan 01 00:00:20 1970 +0000
915 924 summary: z
916 925
917 926 diff --git a/subdir/f1 b/subdir/f1
918 927 --- a/subdir/f1
919 928 +++ b/subdir/f1
920 929 @@ -1,2 +1,3 @@
921 930 a
922 931 a
923 932 +a
924 933
925 934
926 935 Mock "Preserve execute permission on original"
927 936
928 937 $ echo b >> f1
929 938 $ hg record -d '21 0' -maa <<EOF
930 939 > y
931 940 > y
932 941 > y
933 942 > EOF
934 943 diff --git a/subdir/f1 b/subdir/f1
935 944 1 hunks, 1 lines changed
936 945 examine changes to 'subdir/f1'? [Ynesfdaq?]
937 946 @@ -1,3 +1,4 @@
938 947 a
939 948 a
940 949 a
941 950 +b
942 951 record this change to 'subdir/f1'? [Ynesfdaq?]
943 952
944 953 $ hg tip --config diff.git=True -p
945 954 changeset: 23:0eab41a3e524
946 955 tag: tip
947 956 user: test
948 957 date: Thu Jan 01 00:00:21 1970 +0000
949 958 summary: aa
950 959
951 960 diff --git a/subdir/f1 b/subdir/f1
952 961 --- a/subdir/f1
953 962 +++ b/subdir/f1
954 963 @@ -1,3 +1,4 @@
955 964 a
956 965 a
957 966 a
958 967 +b
959 968
960 969
961 970 Mock "Preserve chmod -x"
962 971
963 972 $ chmod -x f1
964 973 $ echo c >> f1
965 974 $ hg record -d '22 0' -mab <<EOF
966 975 > y
967 976 > y
968 977 > y
969 978 > EOF
970 979 diff --git a/subdir/f1 b/subdir/f1
971 980 1 hunks, 1 lines changed
972 981 examine changes to 'subdir/f1'? [Ynesfdaq?]
973 982 @@ -2,3 +2,4 @@
974 983 a
975 984 a
976 985 b
977 986 +c
978 987 record this change to 'subdir/f1'? [Ynesfdaq?]
979 988
980 989 $ hg tip --config diff.git=True -p
981 990 changeset: 24:f4f718f27b7c
982 991 tag: tip
983 992 user: test
984 993 date: Thu Jan 01 00:00:22 1970 +0000
985 994 summary: ab
986 995
987 996 diff --git a/subdir/f1 b/subdir/f1
988 997 --- a/subdir/f1
989 998 +++ b/subdir/f1
990 999 @@ -2,3 +2,4 @@
991 1000 a
992 1001 a
993 1002 b
994 1003 +c
995 1004
996 1005
997 1006 #endif
998 1007
999 1008 $ cd ..
1000 1009
1001 1010
1002 1011 Abort early when a merge is in progress
1003 1012
1004 1013 $ hg up 4
1005 1014 1 files updated, 0 files merged, 6 files removed, 0 files unresolved
1006 1015
1007 1016 $ touch iwillmergethat
1008 1017 $ hg add iwillmergethat
1009 1018
1010 1019 $ hg branch thatbranch
1011 1020 marked working directory as branch thatbranch
1012 1021 (branches are permanent and global, did you want a bookmark?)
1013 1022
1014 1023 $ hg ci -m'new head'
1015 1024
1016 1025 $ hg up default
1017 1026 6 files updated, 0 files merged, 2 files removed, 0 files unresolved
1018 1027
1019 1028 $ hg merge thatbranch
1020 1029 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1021 1030 (branch merge, don't forget to commit)
1022 1031
1023 1032 $ hg record -m'will abort'
1024 1033 abort: cannot partially commit a merge (use "hg commit" instead)
1025 1034 [255]
1026 1035
1027 1036 $ hg up -C
1028 1037 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1029 1038
1030 1039 Editing patch
1031 1040
1032 1041 $ cat > editor.sh << '__EOF__'
1033 1042 > sed -e 7d -e '5s/^-/ /' "$1" > tmp
1034 1043 > mv tmp "$1"
1035 1044 > __EOF__
1036 1045 $ cat > editedfile << '__EOF__'
1037 1046 > This is the first line
1038 1047 > This is the second line
1039 1048 > This is the third line
1040 1049 > __EOF__
1041 1050 $ hg add editedfile
1042 1051 $ hg commit -medit-patch-1
1043 1052 $ cat > editedfile << '__EOF__'
1044 1053 > This line has changed
1045 1054 > This change will be committed
1046 1055 > This is the third line
1047 1056 > __EOF__
1048 1057 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record -d '23 0' -medit-patch-2 <<EOF
1049 1058 > y
1050 1059 > e
1051 1060 > EOF
1052 1061 diff --git a/editedfile b/editedfile
1053 1062 1 hunks, 2 lines changed
1054 1063 examine changes to 'editedfile'? [Ynesfdaq?]
1055 1064 @@ -1,3 +1,3 @@
1056 1065 -This is the first line
1057 1066 -This is the second line
1058 1067 +This line has changed
1059 1068 +This change will be committed
1060 1069 This is the third line
1061 1070 record this change to 'editedfile'? [Ynesfdaq?]
1062 1071 $ cat editedfile
1063 1072 This line has changed
1064 1073 This change will be committed
1065 1074 This is the third line
1066 1075 $ hg cat -r tip editedfile
1067 1076 This is the first line
1068 1077 This change will be committed
1069 1078 This is the third line
1070 1079 $ hg revert editedfile
1071 1080
1072 1081 Trying to edit patch for whole file
1073 1082
1074 1083 $ echo "This is the fourth line" >> editedfile
1075 1084 $ hg record <<EOF
1076 1085 > e
1077 1086 > q
1078 1087 > EOF
1079 1088 diff --git a/editedfile b/editedfile
1080 1089 1 hunks, 1 lines changed
1081 1090 examine changes to 'editedfile'? [Ynesfdaq?]
1082 1091 cannot edit patch for whole file
1083 1092 examine changes to 'editedfile'? [Ynesfdaq?]
1084 1093 abort: user quit
1085 1094 [255]
1086 1095 $ hg revert editedfile
1087 1096
1088 1097 Removing changes from patch
1089 1098
1090 1099 $ sed -e '3s/third/second/' -e '2s/will/will not/' -e 1d editedfile > tmp
1091 1100 $ mv tmp editedfile
1092 1101 $ echo "This line has been added" >> editedfile
1093 1102 $ cat > editor.sh << '__EOF__'
1094 1103 > sed -e 's/^[-+]/ /' "$1" > tmp
1095 1104 > mv tmp "$1"
1096 1105 > __EOF__
1097 1106 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record <<EOF
1098 1107 > y
1099 1108 > e
1100 1109 > EOF
1101 1110 diff --git a/editedfile b/editedfile
1102 1111 1 hunks, 3 lines changed
1103 1112 examine changes to 'editedfile'? [Ynesfdaq?]
1104 1113 @@ -1,3 +1,3 @@
1105 1114 -This is the first line
1106 1115 -This change will be committed
1107 1116 -This is the third line
1108 1117 +This change will not be committed
1109 1118 +This is the second line
1110 1119 +This line has been added
1111 1120 record this change to 'editedfile'? [Ynesfdaq?]
1112 1121 no changes to record
1113 1122 $ cat editedfile
1114 1123 This change will not be committed
1115 1124 This is the second line
1116 1125 This line has been added
1117 1126 $ hg cat -r tip editedfile
1118 1127 This is the first line
1119 1128 This change will be committed
1120 1129 This is the third line
1121 1130 $ hg revert editedfile
1122 1131
1123 1132 Invalid patch
1124 1133
1125 1134 $ sed -e '3s/third/second/' -e '2s/will/will not/' -e 1d editedfile > tmp
1126 1135 $ mv tmp editedfile
1127 1136 $ echo "This line has been added" >> editedfile
1128 1137 $ cat > editor.sh << '__EOF__'
1129 1138 > sed s/This/That/ "$1" > tmp
1130 1139 > mv tmp "$1"
1131 1140 > __EOF__
1132 1141 $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg record <<EOF
1133 1142 > y
1134 1143 > e
1135 1144 > EOF
1136 1145 diff --git a/editedfile b/editedfile
1137 1146 1 hunks, 3 lines changed
1138 1147 examine changes to 'editedfile'? [Ynesfdaq?]
1139 1148 @@ -1,3 +1,3 @@
1140 1149 -This is the first line
1141 1150 -This change will be committed
1142 1151 -This is the third line
1143 1152 +This change will not be committed
1144 1153 +This is the second line
1145 1154 +This line has been added
1146 1155 record this change to 'editedfile'? [Ynesfdaq?]
1147 1156 patching file editedfile
1148 1157 Hunk #1 FAILED at 0
1149 1158 1 out of 1 hunks FAILED -- saving rejects to file editedfile.rej
1150 1159 abort: patch failed to apply
1151 1160 [255]
1152 1161 $ cat editedfile
1153 1162 This change will not be committed
1154 1163 This is the second line
1155 1164 This line has been added
1156 1165 $ hg cat -r tip editedfile
1157 1166 This is the first line
1158 1167 This change will be committed
1159 1168 This is the third line
1160 1169 $ cat editedfile.rej
1161 1170 --- editedfile
1162 1171 +++ editedfile
1163 1172 @@ -1,3 +1,3 @@
1164 1173 -That is the first line
1165 1174 -That change will be committed
1166 1175 -That is the third line
1167 1176 +That change will not be committed
1168 1177 +That is the second line
1169 1178 +That line has been added
1170 1179 $ hg up -C
1171 1180 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1172 1181
1173 1182 With win32text
1174 1183
1175 1184 $ echo '[extensions]' >> .hg/hgrc
1176 1185 $ echo 'win32text = ' >> .hg/hgrc
1177 1186 $ echo '[decode]' >> .hg/hgrc
1178 1187 $ echo '** = cleverdecode:' >> .hg/hgrc
1179 1188 $ echo '[encode]' >> .hg/hgrc
1180 1189 $ echo '** = cleverencode:' >> .hg/hgrc
1181 1190 $ echo '[patch]' >> .hg/hgrc
1182 1191 $ echo 'eol = crlf' >> .hg/hgrc
1183 1192
1184 1193 Ignore win32text deprecation warning for now:
1185 1194
1186 1195 $ echo '[win32text]' >> .hg/hgrc
1187 1196 $ echo 'warn = no' >> .hg/hgrc
1188 1197
1189 1198 $ echo d >> subdir/f1
1190 1199 $ hg record -d '24 0' -mw1 <<EOF
1191 1200 > y
1192 1201 > y
1193 1202 > EOF
1194 1203 diff --git a/subdir/f1 b/subdir/f1
1195 1204 1 hunks, 1 lines changed
1196 1205 examine changes to 'subdir/f1'? [Ynesfdaq?]
1197 1206 @@ -3,3 +3,4 @@
1198 1207 a
1199 1208 b
1200 1209 c
1201 1210 +d
1202 1211 record this change to 'subdir/f1'? [Ynesfdaq?]
1203 1212
1204 1213 $ hg tip -p
1205 1214 changeset: 28:* (glob)
1206 1215 tag: tip
1207 1216 user: test
1208 1217 date: Thu Jan 01 00:00:24 1970 +0000
1209 1218 summary: w1
1210 1219
1211 1220 diff -r ???????????? -r ???????????? subdir/f1 (glob)
1212 1221 --- a/subdir/f1 Thu Jan 01 00:00:23 1970 +0000
1213 1222 +++ b/subdir/f1 Thu Jan 01 00:00:24 1970 +0000
1214 1223 @@ -3,3 +3,4 @@
1215 1224 a
1216 1225 b
1217 1226 c
1218 1227 +d
1219 1228
1220 1229
1221 1230 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now