##// END OF EJS Templates
phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs -
r50322:c4417029 default
parent child Browse files
Show More
@@ -1,1210 +1,1217 b''
1 1 # shelve.py - save/restore working directory state
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 """save and restore changes to the working directory
9 9
10 10 The "hg shelve" command saves changes made to the working directory
11 11 and reverts those changes, resetting the working directory to a clean
12 12 state.
13 13
14 14 Later on, the "hg unshelve" command restores the changes saved by "hg
15 15 shelve". Changes can be restored even after updating to a different
16 16 parent, in which case Mercurial's merge machinery will resolve any
17 17 conflicts if necessary.
18 18
19 19 You can have more than one shelved change outstanding at a time; each
20 20 shelved change has a distinct name. For details, see the help for "hg
21 21 shelve".
22 22 """
23 23
24 24 import collections
25 25 import io
26 26 import itertools
27 27 import stat
28 28
29 29 from .i18n import _
30 30 from .node import (
31 31 bin,
32 32 hex,
33 33 nullrev,
34 34 )
35 35 from . import (
36 36 bookmarks,
37 37 bundle2,
38 38 changegroup,
39 39 cmdutil,
40 40 discovery,
41 41 error,
42 42 exchange,
43 43 hg,
44 44 lock as lockmod,
45 45 mdiff,
46 46 merge,
47 47 mergestate as mergestatemod,
48 48 patch,
49 49 phases,
50 50 pycompat,
51 51 repair,
52 52 scmutil,
53 53 templatefilters,
54 54 util,
55 55 vfs as vfsmod,
56 56 )
57 57 from .utils import (
58 58 dateutil,
59 59 stringutil,
60 60 )
61 61
62 62 backupdir = b'shelve-backup'
63 63 shelvedir = b'shelved'
64 64 shelvefileextensions = [b'hg', b'patch', b'shelve']
65 65
66 66 # we never need the user, so we use a
67 67 # generic user for all shelve operations
68 68 shelveuser = b'shelve@localhost'
69 69
70 70
71 71 class ShelfDir:
72 72 def __init__(self, repo, for_backups=False):
73 73 if for_backups:
74 74 self.vfs = vfsmod.vfs(repo.vfs.join(backupdir))
75 75 else:
76 76 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
77 77
78 78 def get(self, name):
79 79 return Shelf(self.vfs, name)
80 80
81 81 def listshelves(self):
82 82 """return all shelves in repo as list of (time, name)"""
83 83 try:
84 84 names = self.vfs.listdir()
85 85 except FileNotFoundError:
86 86 return []
87 87 info = []
88 88 seen = set()
89 89 for filename in names:
90 90 name = filename.rsplit(b'.', 1)[0]
91 91 if name in seen:
92 92 continue
93 93 seen.add(name)
94 94 shelf = self.get(name)
95 95 if not shelf.exists():
96 96 continue
97 97 mtime = shelf.mtime()
98 98 info.append((mtime, name))
99 99 return sorted(info, reverse=True)
100 100
101 101
102 102 class Shelf:
103 103 """Represents a shelf, including possibly multiple files storing it.
104 104
105 105 Old shelves will have a .patch and a .hg file. Newer shelves will
106 106 also have a .shelve file. This class abstracts away some of the
107 107 differences and lets you work with the shelf as a whole.
108 108 """
109 109
110 110 def __init__(self, vfs, name):
111 111 self.vfs = vfs
112 112 self.name = name
113 113
114 114 def exists(self):
115 return self.vfs.exists(self.name + b'.patch') and self.vfs.exists(
116 self.name + b'.hg'
117 )
115 return self._exists(b'.shelve') or self._exists(b'.patch', b'.hg')
116
117 def _exists(self, *exts):
118 return all(self.vfs.exists(self.name + ext) for ext in exts)
118 119
119 120 def mtime(self):
120 return self.vfs.stat(self.name + b'.patch')[stat.ST_MTIME]
121 try:
122 return self._stat(b'.shelve')[stat.ST_MTIME]
123 except FileNotFoundError:
124 return self._stat(b'.patch')[stat.ST_MTIME]
125
126 def _stat(self, ext):
127 return self.vfs.stat(self.name + ext)
121 128
122 129 def writeinfo(self, info):
123 130 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info)
124 131
125 132 def hasinfo(self):
126 133 return self.vfs.exists(self.name + b'.shelve')
127 134
128 135 def readinfo(self):
129 136 return scmutil.simplekeyvaluefile(
130 137 self.vfs, self.name + b'.shelve'
131 138 ).read()
132 139
133 140 def writebundle(self, repo, bases, node):
134 141 cgversion = changegroup.safeversion(repo)
135 142 if cgversion == b'01':
136 143 btype = b'HG10BZ'
137 144 compression = None
138 145 else:
139 146 btype = b'HG20'
140 147 compression = b'BZ'
141 148
142 149 repo = repo.unfiltered()
143 150
144 151 outgoing = discovery.outgoing(
145 152 repo, missingroots=bases, ancestorsof=[node]
146 153 )
147 154 cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve')
148 155
149 156 bundle_filename = self.vfs.join(self.name + b'.hg')
150 157 bundle2.writebundle(
151 158 repo.ui,
152 159 cg,
153 160 bundle_filename,
154 161 btype,
155 162 self.vfs,
156 163 compression=compression,
157 164 )
158 165
159 166 def applybundle(self, repo, tr):
160 167 filename = self.name + b'.hg'
161 168 fp = self.vfs(filename)
162 169 try:
163 170 targetphase = phases.internal
164 171 if not phases.supportinternal(repo):
165 172 targetphase = phases.secret
166 173 gen = exchange.readbundle(repo.ui, fp, filename, self.vfs)
167 174 pretip = repo[b'tip']
168 175 bundle2.applybundle(
169 176 repo,
170 177 gen,
171 178 tr,
172 179 source=b'unshelve',
173 180 url=b'bundle:' + self.vfs.join(filename),
174 181 targetphase=targetphase,
175 182 )
176 183 shelvectx = repo[b'tip']
177 184 if pretip == shelvectx:
178 185 shelverev = tr.changes[b'revduplicates'][-1]
179 186 shelvectx = repo[shelverev]
180 187 return shelvectx
181 188 finally:
182 189 fp.close()
183 190
184 191 def open_patch(self, mode=b'rb'):
185 192 return self.vfs(self.name + b'.patch', mode)
186 193
187 194 def patch_from_node(self, repo, node):
188 195 repo = repo.unfiltered()
189 196 match = _optimized_match(repo, node)
190 197 fp = io.BytesIO()
191 198 cmdutil.exportfile(
192 199 repo,
193 200 [node],
194 201 fp,
195 202 opts=mdiff.diffopts(git=True),
196 203 match=match,
197 204 )
198 205 fp.seek(0)
199 206 return fp
200 207
201 208 def load_patch(self, repo):
202 209 try:
203 210 # prefer node-based shelf
204 211 return self.patch_from_node(repo, self.readinfo()[b'node'])
205 212 except (FileNotFoundError, error.RepoLookupError):
206 213 return self.open_patch()
207 214
208 215 def _backupfilename(self, backupvfs, filename):
209 216 def gennames(base):
210 217 yield base
211 218 base, ext = base.rsplit(b'.', 1)
212 219 for i in itertools.count(1):
213 220 yield b'%s-%d.%s' % (base, i, ext)
214 221
215 222 for n in gennames(filename):
216 223 if not backupvfs.exists(n):
217 224 return backupvfs.join(n)
218 225
219 226 def movetobackup(self, backupvfs):
220 227 if not backupvfs.isdir():
221 228 backupvfs.makedir()
222 229 for suffix in shelvefileextensions:
223 230 filename = self.name + b'.' + suffix
224 231 if self.vfs.exists(filename):
225 232 util.rename(
226 233 self.vfs.join(filename),
227 234 self._backupfilename(backupvfs, filename),
228 235 )
229 236
230 237 def delete(self):
231 238 for ext in shelvefileextensions:
232 239 self.vfs.tryunlink(self.name + b'.' + ext)
233 240
234 241
235 242 def _optimized_match(repo, node):
236 243 """
237 244 Create a matcher so that prefetch doesn't attempt to fetch
238 245 the entire repository pointlessly, and as an optimisation
239 246 for movedirstate, if needed.
240 247 """
241 248 return scmutil.matchfiles(repo, repo[node].files())
242 249
243 250
244 251 class shelvedstate:
245 252 """Handle persistence during unshelving operations.
246 253
247 254 Handles saving and restoring a shelved state. Ensures that different
248 255 versions of a shelved state are possible and handles them appropriately.
249 256 """
250 257
251 258 _version = 2
252 259 _filename = b'shelvedstate'
253 260 _keep = b'keep'
254 261 _nokeep = b'nokeep'
255 262 # colon is essential to differentiate from a real bookmark name
256 263 _noactivebook = b':no-active-bookmark'
257 264 _interactive = b'interactive'
258 265
259 266 @classmethod
260 267 def _verifyandtransform(cls, d):
261 268 """Some basic shelvestate syntactic verification and transformation"""
262 269 try:
263 270 d[b'originalwctx'] = bin(d[b'originalwctx'])
264 271 d[b'pendingctx'] = bin(d[b'pendingctx'])
265 272 d[b'parents'] = [bin(h) for h in d[b'parents'].split(b' ')]
266 273 d[b'nodestoremove'] = [
267 274 bin(h) for h in d[b'nodestoremove'].split(b' ')
268 275 ]
269 276 except (ValueError, KeyError) as err:
270 277 raise error.CorruptedState(stringutil.forcebytestr(err))
271 278
272 279 @classmethod
273 280 def _getversion(cls, repo):
274 281 """Read version information from shelvestate file"""
275 282 fp = repo.vfs(cls._filename)
276 283 try:
277 284 version = int(fp.readline().strip())
278 285 except ValueError as err:
279 286 raise error.CorruptedState(stringutil.forcebytestr(err))
280 287 finally:
281 288 fp.close()
282 289 return version
283 290
284 291 @classmethod
285 292 def _readold(cls, repo):
286 293 """Read the old position-based version of a shelvestate file"""
287 294 # Order is important, because old shelvestate file uses it
288 295 # to detemine values of fields (i.g. name is on the second line,
289 296 # originalwctx is on the third and so forth). Please do not change.
290 297 keys = [
291 298 b'version',
292 299 b'name',
293 300 b'originalwctx',
294 301 b'pendingctx',
295 302 b'parents',
296 303 b'nodestoremove',
297 304 b'branchtorestore',
298 305 b'keep',
299 306 b'activebook',
300 307 ]
301 308 # this is executed only seldomly, so it is not a big deal
302 309 # that we open this file twice
303 310 fp = repo.vfs(cls._filename)
304 311 d = {}
305 312 try:
306 313 for key in keys:
307 314 d[key] = fp.readline().strip()
308 315 finally:
309 316 fp.close()
310 317 return d
311 318
312 319 @classmethod
313 320 def load(cls, repo):
314 321 version = cls._getversion(repo)
315 322 if version < cls._version:
316 323 d = cls._readold(repo)
317 324 elif version == cls._version:
318 325 d = scmutil.simplekeyvaluefile(repo.vfs, cls._filename).read(
319 326 firstlinenonkeyval=True
320 327 )
321 328 else:
322 329 raise error.Abort(
323 330 _(
324 331 b'this version of shelve is incompatible '
325 332 b'with the version used in this repo'
326 333 )
327 334 )
328 335
329 336 cls._verifyandtransform(d)
330 337 try:
331 338 obj = cls()
332 339 obj.name = d[b'name']
333 340 obj.wctx = repo[d[b'originalwctx']]
334 341 obj.pendingctx = repo[d[b'pendingctx']]
335 342 obj.parents = d[b'parents']
336 343 obj.nodestoremove = d[b'nodestoremove']
337 344 obj.branchtorestore = d.get(b'branchtorestore', b'')
338 345 obj.keep = d.get(b'keep') == cls._keep
339 346 obj.activebookmark = b''
340 347 if d.get(b'activebook', b'') != cls._noactivebook:
341 348 obj.activebookmark = d.get(b'activebook', b'')
342 349 obj.interactive = d.get(b'interactive') == cls._interactive
343 350 except (error.RepoLookupError, KeyError) as err:
344 351 raise error.CorruptedState(pycompat.bytestr(err))
345 352
346 353 return obj
347 354
348 355 @classmethod
349 356 def save(
350 357 cls,
351 358 repo,
352 359 name,
353 360 originalwctx,
354 361 pendingctx,
355 362 nodestoremove,
356 363 branchtorestore,
357 364 keep=False,
358 365 activebook=b'',
359 366 interactive=False,
360 367 ):
361 368 info = {
362 369 b"name": name,
363 370 b"originalwctx": hex(originalwctx.node()),
364 371 b"pendingctx": hex(pendingctx.node()),
365 372 b"parents": b' '.join([hex(p) for p in repo.dirstate.parents()]),
366 373 b"nodestoremove": b' '.join([hex(n) for n in nodestoremove]),
367 374 b"branchtorestore": branchtorestore,
368 375 b"keep": cls._keep if keep else cls._nokeep,
369 376 b"activebook": activebook or cls._noactivebook,
370 377 }
371 378 if interactive:
372 379 info[b'interactive'] = cls._interactive
373 380 scmutil.simplekeyvaluefile(repo.vfs, cls._filename).write(
374 381 info, firstline=(b"%d" % cls._version)
375 382 )
376 383
377 384 @classmethod
378 385 def clear(cls, repo):
379 386 repo.vfs.unlinkpath(cls._filename, ignoremissing=True)
380 387
381 388
382 389 def cleanupoldbackups(repo):
383 390 maxbackups = repo.ui.configint(b'shelve', b'maxbackups')
384 391 backup_dir = ShelfDir(repo, for_backups=True)
385 392 hgfiles = backup_dir.listshelves()
386 393 if maxbackups > 0 and maxbackups < len(hgfiles):
387 394 bordermtime = hgfiles[maxbackups - 1][0]
388 395 else:
389 396 bordermtime = None
390 397 for mtime, name in hgfiles[maxbackups:]:
391 398 if mtime == bordermtime:
392 399 # keep it, because timestamp can't decide exact order of backups
393 400 continue
394 401 backup_dir.get(name).delete()
395 402
396 403
397 404 def _backupactivebookmark(repo):
398 405 activebookmark = repo._activebookmark
399 406 if activebookmark:
400 407 bookmarks.deactivate(repo)
401 408 return activebookmark
402 409
403 410
404 411 def _restoreactivebookmark(repo, mark):
405 412 if mark:
406 413 bookmarks.activate(repo, mark)
407 414
408 415
409 416 def _aborttransaction(repo, tr):
410 417 """Abort current transaction for shelve/unshelve, but keep dirstate"""
411 418 dirstatebackupname = b'dirstate.shelve'
412 419 repo.dirstate.savebackup(tr, dirstatebackupname)
413 420 tr.abort()
414 421 repo.dirstate.restorebackup(None, dirstatebackupname)
415 422
416 423
417 424 def getshelvename(repo, parent, opts):
418 425 """Decide on the name this shelve is going to have"""
419 426
420 427 def gennames():
421 428 yield label
422 429 for i in itertools.count(1):
423 430 yield b'%s-%02d' % (label, i)
424 431
425 432 name = opts.get(b'name')
426 433 label = repo._activebookmark or parent.branch() or b'default'
427 434 # slashes aren't allowed in filenames, therefore we rename it
428 435 label = label.replace(b'/', b'_')
429 436 label = label.replace(b'\\', b'_')
430 437 # filenames must not start with '.' as it should not be hidden
431 438 if label.startswith(b'.'):
432 439 label = label.replace(b'.', b'_', 1)
433 440
434 441 if name:
435 442 if ShelfDir(repo).get(name).exists():
436 443 e = _(b"a shelved change named '%s' already exists") % name
437 444 raise error.Abort(e)
438 445
439 446 # ensure we are not creating a subdirectory or a hidden file
440 447 if b'/' in name or b'\\' in name:
441 448 raise error.Abort(
442 449 _(b'shelved change names can not contain slashes')
443 450 )
444 451 if name.startswith(b'.'):
445 452 raise error.Abort(_(b"shelved change names can not start with '.'"))
446 453
447 454 else:
448 455 shelf_dir = ShelfDir(repo)
449 456 for n in gennames():
450 457 if not shelf_dir.get(n).exists():
451 458 name = n
452 459 break
453 460
454 461 return name
455 462
456 463
457 464 def mutableancestors(ctx):
458 465 """return all mutable ancestors for ctx (included)
459 466
460 467 Much faster than the revset ancestors(ctx) & draft()"""
461 468 seen = {nullrev}
462 469 visit = collections.deque()
463 470 visit.append(ctx)
464 471 while visit:
465 472 ctx = visit.popleft()
466 473 yield ctx.node()
467 474 for parent in ctx.parents():
468 475 rev = parent.rev()
469 476 if rev not in seen:
470 477 seen.add(rev)
471 478 if parent.mutable():
472 479 visit.append(parent)
473 480
474 481
475 482 def getcommitfunc(extra, interactive, editor=False):
476 483 def commitfunc(ui, repo, message, match, opts):
477 484 hasmq = util.safehasattr(repo, b'mq')
478 485 if hasmq:
479 486 saved, repo.mq.checkapplied = repo.mq.checkapplied, False
480 487
481 488 targetphase = phases.internal
482 489 if not phases.supportinternal(repo):
483 490 targetphase = phases.secret
484 491 overrides = {(b'phases', b'new-commit'): targetphase}
485 492 try:
486 493 editor_ = False
487 494 if editor:
488 495 editor_ = cmdutil.getcommiteditor(
489 496 editform=b'shelve.shelve', **pycompat.strkwargs(opts)
490 497 )
491 498 with repo.ui.configoverride(overrides):
492 499 return repo.commit(
493 500 message,
494 501 shelveuser,
495 502 opts.get(b'date'),
496 503 match,
497 504 editor=editor_,
498 505 extra=extra,
499 506 )
500 507 finally:
501 508 if hasmq:
502 509 repo.mq.checkapplied = saved
503 510
504 511 def interactivecommitfunc(ui, repo, *pats, **opts):
505 512 opts = pycompat.byteskwargs(opts)
506 513 match = scmutil.match(repo[b'.'], pats, {})
507 514 message = opts[b'message']
508 515 return commitfunc(ui, repo, message, match, opts)
509 516
510 517 return interactivecommitfunc if interactive else commitfunc
511 518
512 519
513 520 def _nothingtoshelvemessaging(ui, repo, pats, opts):
514 521 stat = repo.status(match=scmutil.match(repo[None], pats, opts))
515 522 if stat.deleted:
516 523 ui.status(
517 524 _(b"nothing changed (%d missing files, see 'hg status')\n")
518 525 % len(stat.deleted)
519 526 )
520 527 else:
521 528 ui.status(_(b"nothing changed\n"))
522 529
523 530
524 531 def _shelvecreatedcommit(repo, node, name, match):
525 532 info = {b'node': hex(node)}
526 533 shelf = ShelfDir(repo).get(name)
527 534 shelf.writeinfo(info)
528 535 bases = list(mutableancestors(repo[node]))
529 536 shelf.writebundle(repo, bases, node)
530 537 with shelf.open_patch(b'wb') as fp:
531 538 cmdutil.exportfile(
532 539 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match
533 540 )
534 541
535 542
536 543 def _includeunknownfiles(repo, pats, opts, extra):
537 544 s = repo.status(match=scmutil.match(repo[None], pats, opts), unknown=True)
538 545 if s.unknown:
539 546 extra[b'shelve_unknown'] = b'\0'.join(s.unknown)
540 547 repo[None].add(s.unknown)
541 548
542 549
543 550 def _finishshelve(repo, tr):
544 551 if phases.supportinternal(repo):
545 552 tr.close()
546 553 else:
547 554 _aborttransaction(repo, tr)
548 555
549 556
550 557 def createcmd(ui, repo, pats, opts):
551 558 """subcommand that creates a new shelve"""
552 559 with repo.wlock():
553 560 cmdutil.checkunfinished(repo)
554 561 return _docreatecmd(ui, repo, pats, opts)
555 562
556 563
557 564 def _docreatecmd(ui, repo, pats, opts):
558 565 wctx = repo[None]
559 566 parents = wctx.parents()
560 567 parent = parents[0]
561 568 origbranch = wctx.branch()
562 569
563 570 if parent.rev() != nullrev:
564 571 desc = b"changes to: %s" % parent.description().split(b'\n', 1)[0]
565 572 else:
566 573 desc = b'(changes in empty repository)'
567 574
568 575 if not opts.get(b'message'):
569 576 opts[b'message'] = desc
570 577
571 578 lock = tr = activebookmark = None
572 579 try:
573 580 lock = repo.lock()
574 581
575 582 # use an uncommitted transaction to generate the bundle to avoid
576 583 # pull races. ensure we don't print the abort message to stderr.
577 584 tr = repo.transaction(b'shelve', report=lambda x: None)
578 585
579 586 interactive = opts.get(b'interactive', False)
580 587 includeunknown = opts.get(b'unknown', False) and not opts.get(
581 588 b'addremove', False
582 589 )
583 590
584 591 name = getshelvename(repo, parent, opts)
585 592 activebookmark = _backupactivebookmark(repo)
586 593 extra = {b'internal': b'shelve'}
587 594 if includeunknown:
588 595 _includeunknownfiles(repo, pats, opts, extra)
589 596
590 597 if _iswctxonnewbranch(repo) and not _isbareshelve(pats, opts):
591 598 # In non-bare shelve we don't store newly created branch
592 599 # at bundled commit
593 600 repo.dirstate.setbranch(repo[b'.'].branch())
594 601
595 602 commitfunc = getcommitfunc(extra, interactive, editor=True)
596 603 if not interactive:
597 604 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
598 605 else:
599 606 node = cmdutil.dorecord(
600 607 ui,
601 608 repo,
602 609 commitfunc,
603 610 None,
604 611 False,
605 612 cmdutil.recordfilter,
606 613 *pats,
607 614 **pycompat.strkwargs(opts)
608 615 )
609 616 if not node:
610 617 _nothingtoshelvemessaging(ui, repo, pats, opts)
611 618 return 1
612 619
613 620 match = _optimized_match(repo, node)
614 621 _shelvecreatedcommit(repo, node, name, match)
615 622
616 623 ui.status(_(b'shelved as %s\n') % name)
617 624 if opts[b'keep']:
618 625 with repo.dirstate.parentchange():
619 626 scmutil.movedirstate(repo, parent, match)
620 627 else:
621 628 hg.update(repo, parent.node())
622 629 ms = mergestatemod.mergestate.read(repo)
623 630 if not ms.unresolvedcount():
624 631 ms.reset()
625 632
626 633 if origbranch != repo[b'.'].branch() and not _isbareshelve(pats, opts):
627 634 repo.dirstate.setbranch(origbranch)
628 635
629 636 _finishshelve(repo, tr)
630 637 finally:
631 638 _restoreactivebookmark(repo, activebookmark)
632 639 lockmod.release(tr, lock)
633 640
634 641
635 642 def _isbareshelve(pats, opts):
636 643 return (
637 644 not pats
638 645 and not opts.get(b'interactive', False)
639 646 and not opts.get(b'include', False)
640 647 and not opts.get(b'exclude', False)
641 648 )
642 649
643 650
644 651 def _iswctxonnewbranch(repo):
645 652 return repo[None].branch() != repo[b'.'].branch()
646 653
647 654
648 655 def cleanupcmd(ui, repo):
649 656 """subcommand that deletes all shelves"""
650 657
651 658 with repo.wlock():
652 659 shelf_dir = ShelfDir(repo)
653 660 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
654 661 for _mtime, name in shelf_dir.listshelves():
655 662 shelf_dir.get(name).movetobackup(backupvfs)
656 663 cleanupoldbackups(repo)
657 664
658 665
659 666 def deletecmd(ui, repo, pats):
660 667 """subcommand that deletes a specific shelve"""
661 668 if not pats:
662 669 raise error.InputError(_(b'no shelved changes specified!'))
663 670 with repo.wlock():
664 671 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
665 672 for name in pats:
666 673 shelf = ShelfDir(repo).get(name)
667 674 if not shelf.exists():
668 675 raise error.InputError(
669 676 _(b"shelved change '%s' not found") % name
670 677 )
671 678 shelf.movetobackup(backupvfs)
672 679 cleanupoldbackups(repo)
673 680
674 681
675 682 def listcmd(ui, repo, pats, opts):
676 683 """subcommand that displays the list of shelves"""
677 684 pats = set(pats)
678 685 width = 80
679 686 if not ui.plain():
680 687 width = ui.termwidth()
681 688 namelabel = b'shelve.newest'
682 689 ui.pager(b'shelve')
683 690 shelf_dir = ShelfDir(repo)
684 691 for mtime, name in shelf_dir.listshelves():
685 692 if pats and name not in pats:
686 693 continue
687 694 ui.write(name, label=namelabel)
688 695 namelabel = b'shelve.name'
689 696 if ui.quiet:
690 697 ui.write(b'\n')
691 698 continue
692 699 ui.write(b' ' * (16 - len(name)))
693 700 used = 16
694 701 date = dateutil.makedate(mtime)
695 702 age = b'(%s)' % templatefilters.age(date, abbrev=True)
696 703 ui.write(age, label=b'shelve.age')
697 704 ui.write(b' ' * (12 - len(age)))
698 705 used += 12
699 706 with shelf_dir.get(name).load_patch(repo) as fp:
700 707 while True:
701 708 line = fp.readline()
702 709 if not line:
703 710 break
704 711 if not line.startswith(b'#'):
705 712 desc = line.rstrip()
706 713 if ui.formatted():
707 714 desc = stringutil.ellipsis(desc, width - used)
708 715 ui.write(desc)
709 716 break
710 717 ui.write(b'\n')
711 718 if not (opts[b'patch'] or opts[b'stat']):
712 719 continue
713 720 difflines = fp.readlines()
714 721 if opts[b'patch']:
715 722 for chunk, label in patch.difflabel(iter, difflines):
716 723 ui.write(chunk, label=label)
717 724 if opts[b'stat']:
718 725 for chunk, label in patch.diffstatui(difflines, width=width):
719 726 ui.write(chunk, label=label)
720 727
721 728
722 729 def patchcmds(ui, repo, pats, opts):
723 730 """subcommand that displays shelves"""
724 731 shelf_dir = ShelfDir(repo)
725 732 if len(pats) == 0:
726 733 shelves = shelf_dir.listshelves()
727 734 if not shelves:
728 735 raise error.Abort(_(b"there are no shelves to show"))
729 736 mtime, name = shelves[0]
730 737 pats = [name]
731 738
732 739 for shelfname in pats:
733 740 if not shelf_dir.get(shelfname).exists():
734 741 raise error.Abort(_(b"cannot find shelf %s") % shelfname)
735 742
736 743 listcmd(ui, repo, pats, opts)
737 744
738 745
739 746 def checkparents(repo, state):
740 747 """check parent while resuming an unshelve"""
741 748 if state.parents != repo.dirstate.parents():
742 749 raise error.Abort(
743 750 _(b'working directory parents do not match unshelve state')
744 751 )
745 752
746 753
747 754 def _loadshelvedstate(ui, repo, opts):
748 755 try:
749 756 state = shelvedstate.load(repo)
750 757 if opts.get(b'keep') is None:
751 758 opts[b'keep'] = state.keep
752 759 except FileNotFoundError:
753 760 cmdutil.wrongtooltocontinue(repo, _(b'unshelve'))
754 761 except error.CorruptedState as err:
755 762 ui.debug(pycompat.bytestr(err) + b'\n')
756 763 if opts.get(b'continue'):
757 764 msg = _(b'corrupted shelved state file')
758 765 hint = _(
759 766 b'please run hg unshelve --abort to abort unshelve '
760 767 b'operation'
761 768 )
762 769 raise error.Abort(msg, hint=hint)
763 770 elif opts.get(b'abort'):
764 771 shelvedstate.clear(repo)
765 772 raise error.Abort(
766 773 _(
767 774 b'could not read shelved state file, your '
768 775 b'working copy may be in an unexpected state\n'
769 776 b'please update to some commit\n'
770 777 )
771 778 )
772 779 return state
773 780
774 781
775 782 def unshelveabort(ui, repo, state):
776 783 """subcommand that abort an in-progress unshelve"""
777 784 with repo.lock():
778 785 try:
779 786 checkparents(repo, state)
780 787
781 788 merge.clean_update(state.pendingctx)
782 789 if state.activebookmark and state.activebookmark in repo._bookmarks:
783 790 bookmarks.activate(repo, state.activebookmark)
784 791 mergefiles(ui, repo, state.wctx, state.pendingctx)
785 792 if not phases.supportinternal(repo):
786 793 repair.strip(
787 794 ui, repo, state.nodestoremove, backup=False, topic=b'shelve'
788 795 )
789 796 finally:
790 797 shelvedstate.clear(repo)
791 798 ui.warn(_(b"unshelve of '%s' aborted\n") % state.name)
792 799
793 800
794 801 def hgabortunshelve(ui, repo):
795 802 """logic to abort unshelve using 'hg abort"""
796 803 with repo.wlock():
797 804 state = _loadshelvedstate(ui, repo, {b'abort': True})
798 805 return unshelveabort(ui, repo, state)
799 806
800 807
801 808 def mergefiles(ui, repo, wctx, shelvectx):
802 809 """updates to wctx and merges the changes from shelvectx into the
803 810 dirstate."""
804 811 with ui.configoverride({(b'ui', b'quiet'): True}):
805 812 hg.update(repo, wctx.node())
806 813 cmdutil.revert(ui, repo, shelvectx)
807 814
808 815
809 816 def restorebranch(ui, repo, branchtorestore):
810 817 if branchtorestore and branchtorestore != repo.dirstate.branch():
811 818 repo.dirstate.setbranch(branchtorestore)
812 819 ui.status(
813 820 _(b'marked working directory as branch %s\n') % branchtorestore
814 821 )
815 822
816 823
817 824 def unshelvecleanup(ui, repo, name, opts):
818 825 """remove related files after an unshelve"""
819 826 if not opts.get(b'keep'):
820 827 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
821 828 ShelfDir(repo).get(name).movetobackup(backupvfs)
822 829 cleanupoldbackups(repo)
823 830
824 831
825 832 def unshelvecontinue(ui, repo, state, opts):
826 833 """subcommand to continue an in-progress unshelve"""
827 834 # We're finishing off a merge. First parent is our original
828 835 # parent, second is the temporary "fake" commit we're unshelving.
829 836 interactive = state.interactive
830 837 basename = state.name
831 838 with repo.lock():
832 839 checkparents(repo, state)
833 840 ms = mergestatemod.mergestate.read(repo)
834 841 if ms.unresolvedcount():
835 842 raise error.Abort(
836 843 _(b"unresolved conflicts, can't continue"),
837 844 hint=_(b"see 'hg resolve', then 'hg unshelve --continue'"),
838 845 )
839 846
840 847 shelvectx = repo[state.parents[1]]
841 848 pendingctx = state.pendingctx
842 849
843 850 with repo.dirstate.parentchange():
844 851 repo.setparents(state.pendingctx.node(), repo.nullid)
845 852 repo.dirstate.write(repo.currenttransaction())
846 853
847 854 targetphase = phases.internal
848 855 if not phases.supportinternal(repo):
849 856 targetphase = phases.secret
850 857 overrides = {(b'phases', b'new-commit'): targetphase}
851 858 with repo.ui.configoverride(overrides, b'unshelve'):
852 859 with repo.dirstate.parentchange():
853 860 repo.setparents(state.parents[0], repo.nullid)
854 861 newnode, ispartialunshelve = _createunshelvectx(
855 862 ui, repo, shelvectx, basename, interactive, opts
856 863 )
857 864
858 865 if newnode is None:
859 866 shelvectx = state.pendingctx
860 867 msg = _(
861 868 b'note: unshelved changes already existed '
862 869 b'in the working copy\n'
863 870 )
864 871 ui.status(msg)
865 872 else:
866 873 # only strip the shelvectx if we produced one
867 874 state.nodestoremove.append(newnode)
868 875 shelvectx = repo[newnode]
869 876
870 877 merge.update(pendingctx)
871 878 mergefiles(ui, repo, state.wctx, shelvectx)
872 879 restorebranch(ui, repo, state.branchtorestore)
873 880
874 881 if not phases.supportinternal(repo):
875 882 repair.strip(
876 883 ui, repo, state.nodestoremove, backup=False, topic=b'shelve'
877 884 )
878 885 shelvedstate.clear(repo)
879 886 if not ispartialunshelve:
880 887 unshelvecleanup(ui, repo, state.name, opts)
881 888 _restoreactivebookmark(repo, state.activebookmark)
882 889 ui.status(_(b"unshelve of '%s' complete\n") % state.name)
883 890
884 891
885 892 def hgcontinueunshelve(ui, repo):
886 893 """logic to resume unshelve using 'hg continue'"""
887 894 with repo.wlock():
888 895 state = _loadshelvedstate(ui, repo, {b'continue': True})
889 896 return unshelvecontinue(ui, repo, state, {b'keep': state.keep})
890 897
891 898
892 899 def _commitworkingcopychanges(ui, repo, opts, tmpwctx):
893 900 """Temporarily commit working copy changes before moving unshelve commit"""
894 901 # Store pending changes in a commit and remember added in case a shelve
895 902 # contains unknown files that are part of the pending change
896 903 s = repo.status()
897 904 addedbefore = frozenset(s.added)
898 905 if not (s.modified or s.added or s.removed):
899 906 return tmpwctx, addedbefore
900 907 ui.status(
901 908 _(
902 909 b"temporarily committing pending changes "
903 910 b"(restore with 'hg unshelve --abort')\n"
904 911 )
905 912 )
906 913 extra = {b'internal': b'shelve'}
907 914 commitfunc = getcommitfunc(extra=extra, interactive=False, editor=False)
908 915 tempopts = {}
909 916 tempopts[b'message'] = b"pending changes temporary commit"
910 917 tempopts[b'date'] = opts.get(b'date')
911 918 with ui.configoverride({(b'ui', b'quiet'): True}):
912 919 node = cmdutil.commit(ui, repo, commitfunc, [], tempopts)
913 920 tmpwctx = repo[node]
914 921 return tmpwctx, addedbefore
915 922
916 923
917 924 def _unshelverestorecommit(ui, repo, tr, basename):
918 925 """Recreate commit in the repository during the unshelve"""
919 926 repo = repo.unfiltered()
920 927 node = None
921 928 shelf = ShelfDir(repo).get(basename)
922 929 if shelf.hasinfo():
923 930 node = shelf.readinfo()[b'node']
924 931 if node is None or node not in repo:
925 932 with ui.configoverride({(b'ui', b'quiet'): True}):
926 933 shelvectx = shelf.applybundle(repo, tr)
927 934 # We might not strip the unbundled changeset, so we should keep track of
928 935 # the unshelve node in case we need to reuse it (eg: unshelve --keep)
929 936 if node is None:
930 937 info = {b'node': hex(shelvectx.node())}
931 938 shelf.writeinfo(info)
932 939 else:
933 940 shelvectx = repo[node]
934 941
935 942 return repo, shelvectx
936 943
937 944
938 945 def _createunshelvectx(ui, repo, shelvectx, basename, interactive, opts):
939 946 """Handles the creation of unshelve commit and updates the shelve if it
940 947 was partially unshelved.
941 948
942 949 If interactive is:
943 950
944 951 * False: Commits all the changes in the working directory.
945 952 * True: Prompts the user to select changes to unshelve and commit them.
946 953 Update the shelve with remaining changes.
947 954
948 955 Returns the node of the new commit formed and a bool indicating whether
949 956 the shelve was partially unshelved.Creates a commit ctx to unshelve
950 957 interactively or non-interactively.
951 958
952 959 The user might want to unshelve certain changes only from the stored
953 960 shelve in interactive. So, we would create two commits. One with requested
954 961 changes to unshelve at that time and the latter is shelved for future.
955 962
956 963 Here, we return both the newnode which is created interactively and a
957 964 bool to know whether the shelve is partly done or completely done.
958 965 """
959 966 opts[b'message'] = shelvectx.description()
960 967 opts[b'interactive-unshelve'] = True
961 968 pats = []
962 969 if not interactive:
963 970 newnode = repo.commit(
964 971 text=shelvectx.description(),
965 972 extra=shelvectx.extra(),
966 973 user=shelvectx.user(),
967 974 date=shelvectx.date(),
968 975 )
969 976 return newnode, False
970 977
971 978 commitfunc = getcommitfunc(shelvectx.extra(), interactive=True, editor=True)
972 979 newnode = cmdutil.dorecord(
973 980 ui,
974 981 repo,
975 982 commitfunc,
976 983 None,
977 984 False,
978 985 cmdutil.recordfilter,
979 986 *pats,
980 987 **pycompat.strkwargs(opts)
981 988 )
982 989 snode = repo.commit(
983 990 text=shelvectx.description(),
984 991 extra=shelvectx.extra(),
985 992 user=shelvectx.user(),
986 993 )
987 994 if snode:
988 995 m = _optimized_match(repo, snode)
989 996 _shelvecreatedcommit(repo, snode, basename, m)
990 997
991 998 return newnode, bool(snode)
992 999
993 1000
994 1001 def _rebaserestoredcommit(
995 1002 ui,
996 1003 repo,
997 1004 opts,
998 1005 tr,
999 1006 oldtiprev,
1000 1007 basename,
1001 1008 pctx,
1002 1009 tmpwctx,
1003 1010 shelvectx,
1004 1011 branchtorestore,
1005 1012 activebookmark,
1006 1013 ):
1007 1014 """Rebase restored commit from its original location to a destination"""
1008 1015 # If the shelve is not immediately on top of the commit
1009 1016 # we'll be merging with, rebase it to be on top.
1010 1017 interactive = opts.get(b'interactive')
1011 1018 if tmpwctx.node() == shelvectx.p1().node() and not interactive:
1012 1019 # We won't skip on interactive mode because, the user might want to
1013 1020 # unshelve certain changes only.
1014 1021 return shelvectx, False
1015 1022
1016 1023 overrides = {
1017 1024 (b'ui', b'forcemerge'): opts.get(b'tool', b''),
1018 1025 (b'phases', b'new-commit'): phases.secret,
1019 1026 }
1020 1027 with repo.ui.configoverride(overrides, b'unshelve'):
1021 1028 ui.status(_(b'rebasing shelved changes\n'))
1022 1029 stats = merge.graft(
1023 1030 repo,
1024 1031 shelvectx,
1025 1032 labels=[
1026 1033 b'working-copy',
1027 1034 b'shelved change',
1028 1035 b'parent of shelved change',
1029 1036 ],
1030 1037 keepconflictparent=True,
1031 1038 )
1032 1039 if stats.unresolvedcount:
1033 1040 tr.close()
1034 1041
1035 1042 nodestoremove = [
1036 1043 repo.changelog.node(rev) for rev in range(oldtiprev, len(repo))
1037 1044 ]
1038 1045 shelvedstate.save(
1039 1046 repo,
1040 1047 basename,
1041 1048 pctx,
1042 1049 tmpwctx,
1043 1050 nodestoremove,
1044 1051 branchtorestore,
1045 1052 opts.get(b'keep'),
1046 1053 activebookmark,
1047 1054 interactive,
1048 1055 )
1049 1056 raise error.ConflictResolutionRequired(b'unshelve')
1050 1057
1051 1058 with repo.dirstate.parentchange():
1052 1059 repo.setparents(tmpwctx.node(), repo.nullid)
1053 1060 newnode, ispartialunshelve = _createunshelvectx(
1054 1061 ui, repo, shelvectx, basename, interactive, opts
1055 1062 )
1056 1063
1057 1064 if newnode is None:
1058 1065 shelvectx = tmpwctx
1059 1066 msg = _(
1060 1067 b'note: unshelved changes already existed '
1061 1068 b'in the working copy\n'
1062 1069 )
1063 1070 ui.status(msg)
1064 1071 else:
1065 1072 shelvectx = repo[newnode]
1066 1073 merge.update(tmpwctx)
1067 1074
1068 1075 return shelvectx, ispartialunshelve
1069 1076
1070 1077
1071 1078 def _forgetunknownfiles(repo, shelvectx, addedbefore):
1072 1079 # Forget any files that were unknown before the shelve, unknown before
1073 1080 # unshelve started, but are now added.
1074 1081 shelveunknown = shelvectx.extra().get(b'shelve_unknown')
1075 1082 if not shelveunknown:
1076 1083 return
1077 1084 shelveunknown = frozenset(shelveunknown.split(b'\0'))
1078 1085 addedafter = frozenset(repo.status().added)
1079 1086 toforget = (addedafter & shelveunknown) - addedbefore
1080 1087 repo[None].forget(toforget)
1081 1088
1082 1089
1083 1090 def _finishunshelve(repo, oldtiprev, tr, activebookmark):
1084 1091 _restoreactivebookmark(repo, activebookmark)
1085 1092 # The transaction aborting will strip all the commits for us,
1086 1093 # but it doesn't update the inmemory structures, so addchangegroup
1087 1094 # hooks still fire and try to operate on the missing commits.
1088 1095 # Clean up manually to prevent this.
1089 1096 repo.unfiltered().changelog.strip(oldtiprev, tr)
1090 1097 _aborttransaction(repo, tr)
1091 1098
1092 1099
1093 1100 def _checkunshelveuntrackedproblems(ui, repo, shelvectx):
1094 1101 """Check potential problems which may result from working
1095 1102 copy having untracked changes."""
1096 1103 wcdeleted = set(repo.status().deleted)
1097 1104 shelvetouched = set(shelvectx.files())
1098 1105 intersection = wcdeleted.intersection(shelvetouched)
1099 1106 if intersection:
1100 1107 m = _(b"shelved change touches missing files")
1101 1108 hint = _(b"run hg status to see which files are missing")
1102 1109 raise error.Abort(m, hint=hint)
1103 1110
1104 1111
1105 1112 def unshelvecmd(ui, repo, *shelved, **opts):
1106 1113 opts = pycompat.byteskwargs(opts)
1107 1114 abortf = opts.get(b'abort')
1108 1115 continuef = opts.get(b'continue')
1109 1116 interactive = opts.get(b'interactive')
1110 1117 if not abortf and not continuef:
1111 1118 cmdutil.checkunfinished(repo)
1112 1119 shelved = list(shelved)
1113 1120 if opts.get(b"name"):
1114 1121 shelved.append(opts[b"name"])
1115 1122
1116 1123 if interactive and opts.get(b'keep'):
1117 1124 raise error.InputError(
1118 1125 _(b'--keep on --interactive is not yet supported')
1119 1126 )
1120 1127 if abortf or continuef:
1121 1128 if abortf and continuef:
1122 1129 raise error.InputError(_(b'cannot use both abort and continue'))
1123 1130 if shelved:
1124 1131 raise error.InputError(
1125 1132 _(
1126 1133 b'cannot combine abort/continue with '
1127 1134 b'naming a shelved change'
1128 1135 )
1129 1136 )
1130 1137 if abortf and opts.get(b'tool', False):
1131 1138 ui.warn(_(b'tool option will be ignored\n'))
1132 1139
1133 1140 state = _loadshelvedstate(ui, repo, opts)
1134 1141 if abortf:
1135 1142 return unshelveabort(ui, repo, state)
1136 1143 elif continuef and interactive:
1137 1144 raise error.InputError(
1138 1145 _(b'cannot use both continue and interactive')
1139 1146 )
1140 1147 elif continuef:
1141 1148 return unshelvecontinue(ui, repo, state, opts)
1142 1149 elif len(shelved) > 1:
1143 1150 raise error.InputError(_(b'can only unshelve one change at a time'))
1144 1151 elif not shelved:
1145 1152 shelved = ShelfDir(repo).listshelves()
1146 1153 if not shelved:
1147 1154 raise error.StateError(_(b'no shelved changes to apply!'))
1148 1155 basename = shelved[0][1]
1149 1156 ui.status(_(b"unshelving change '%s'\n") % basename)
1150 1157 else:
1151 1158 basename = shelved[0]
1152 1159
1153 1160 if not ShelfDir(repo).get(basename).exists():
1154 1161 raise error.InputError(_(b"shelved change '%s' not found") % basename)
1155 1162
1156 1163 return _dounshelve(ui, repo, basename, opts)
1157 1164
1158 1165
1159 1166 def _dounshelve(ui, repo, basename, opts):
1160 1167 repo = repo.unfiltered()
1161 1168 lock = tr = None
1162 1169 try:
1163 1170 lock = repo.lock()
1164 1171 tr = repo.transaction(b'unshelve', report=lambda x: None)
1165 1172 oldtiprev = len(repo)
1166 1173
1167 1174 pctx = repo[b'.']
1168 1175 tmpwctx = pctx
1169 1176 # The goal is to have a commit structure like so:
1170 1177 # ...-> pctx -> tmpwctx -> shelvectx
1171 1178 # where tmpwctx is an optional commit with the user's pending changes
1172 1179 # and shelvectx is the unshelved changes. Then we merge it all down
1173 1180 # to the original pctx.
1174 1181
1175 1182 activebookmark = _backupactivebookmark(repo)
1176 1183 tmpwctx, addedbefore = _commitworkingcopychanges(
1177 1184 ui, repo, opts, tmpwctx
1178 1185 )
1179 1186 repo, shelvectx = _unshelverestorecommit(ui, repo, tr, basename)
1180 1187 _checkunshelveuntrackedproblems(ui, repo, shelvectx)
1181 1188 branchtorestore = b''
1182 1189 if shelvectx.branch() != shelvectx.p1().branch():
1183 1190 branchtorestore = shelvectx.branch()
1184 1191
1185 1192 shelvectx, ispartialunshelve = _rebaserestoredcommit(
1186 1193 ui,
1187 1194 repo,
1188 1195 opts,
1189 1196 tr,
1190 1197 oldtiprev,
1191 1198 basename,
1192 1199 pctx,
1193 1200 tmpwctx,
1194 1201 shelvectx,
1195 1202 branchtorestore,
1196 1203 activebookmark,
1197 1204 )
1198 1205 overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')}
1199 1206 with ui.configoverride(overrides, b'unshelve'):
1200 1207 mergefiles(ui, repo, pctx, shelvectx)
1201 1208 restorebranch(ui, repo, branchtorestore)
1202 1209 shelvedstate.clear(repo)
1203 1210 _finishunshelve(repo, oldtiprev, tr, activebookmark)
1204 1211 _forgetunknownfiles(repo, shelvectx, addedbefore)
1205 1212 if not ispartialunshelve:
1206 1213 unshelvecleanup(ui, repo, basename, opts)
1207 1214 finally:
1208 1215 if tr:
1209 1216 tr.release()
1210 1217 lockmod.release(lock)
@@ -1,1537 +1,1537 b''
1 1 #testcases stripbased phasebased
2 2
3 3 $ cat <<EOF >> $HGRCPATH
4 4 > [extensions]
5 5 > mq =
6 6 > [defaults]
7 7 > diff = --nodates --git
8 8 > qnew = --date '0 0'
9 9 > [shelve]
10 10 > maxbackups = 2
11 11 > EOF
12 12
13 13 #if phasebased
14 14
15 15 $ cat <<EOF >> $HGRCPATH
16 16 > [format]
17 17 > internal-phase = yes
18 18 > EOF
19 19
20 20 #endif
21 21
22 22 $ hg init repo
23 23 $ cd repo
24 24 $ mkdir a b
25 25 $ echo a > a/a
26 26 $ echo b > b/b
27 27 $ echo c > c
28 28 $ echo d > d
29 29 $ echo x > x
30 30 $ hg addremove -q
31 31
32 32 shelve has a help message
33 33 $ hg shelve -h
34 34 hg shelve [OPTION]... [FILE]...
35 35
36 36 save and set aside changes from the working directory
37 37
38 38 Shelving takes files that "hg status" reports as not clean, saves the
39 39 modifications to a bundle (a shelved change), and reverts the files so
40 40 that their state in the working directory becomes clean.
41 41
42 42 To restore these changes to the working directory, using "hg unshelve";
43 43 this will work even if you switch to a different commit.
44 44
45 45 When no files are specified, "hg shelve" saves all not-clean files. If
46 46 specific files or directories are named, only changes to those files are
47 47 shelved.
48 48
49 49 In bare shelve (when no files are specified, without interactive, include
50 50 and exclude option), shelving remembers information if the working
51 51 directory was on newly created branch, in other words working directory
52 52 was on different branch than its first parent. In this situation
53 53 unshelving restores branch information to the working directory.
54 54
55 55 Each shelved change has a name that makes it easier to find later. The
56 56 name of a shelved change defaults to being based on the active bookmark,
57 57 or if there is no active bookmark, the current named branch. To specify a
58 58 different name, use "--name".
59 59
60 60 To see a list of existing shelved changes, use the "--list" option. For
61 61 each shelved change, this will print its name, age, and description; use "
62 62 --patch" or "--stat" for more details.
63 63
64 64 To delete specific shelved changes, use "--delete". To delete all shelved
65 65 changes, use "--cleanup".
66 66
67 67 options ([+] can be repeated):
68 68
69 69 -A --addremove mark new/missing files as added/removed before
70 70 shelving
71 71 -u --unknown store unknown files in the shelve
72 72 --cleanup delete all shelved changes
73 73 --date DATE shelve with the specified commit date
74 74 -d --delete delete the named shelved change(s)
75 75 -e --edit invoke editor on commit messages
76 76 -k --keep shelve, but keep changes in the working directory
77 77 -l --list list current shelves
78 78 -m --message TEXT use text as shelve message
79 79 -n --name NAME use the given name for the shelved commit
80 80 -p --patch output patches for changes (provide the names of the
81 81 shelved changes as positional arguments)
82 82 -i --interactive interactive mode
83 83 --stat output diffstat-style summary of changes (provide
84 84 the names of the shelved changes as positional
85 85 arguments)
86 86 -I --include PATTERN [+] include names matching the given patterns
87 87 -X --exclude PATTERN [+] exclude names matching the given patterns
88 88 --mq operate on patch repository
89 89
90 90 (some details hidden, use --verbose to show complete help)
91 91
92 92 shelving in an empty repo should be possible
93 93 (this tests also that editor is not invoked, if '--edit' is not
94 94 specified)
95 95
96 96 $ HGEDITOR=cat hg shelve
97 97 shelved as default
98 98 0 files updated, 0 files merged, 5 files removed, 0 files unresolved
99 99
100 100 $ hg unshelve
101 101 unshelving change 'default'
102 102
103 103 $ hg commit -q -m 'initial commit'
104 104
105 105 $ hg shelve
106 106 nothing changed
107 107 [1]
108 108
109 109 make sure shelve files were backed up
110 110
111 111 $ ls .hg/shelve-backup
112 112 default.hg
113 113 default.patch
114 114 default.shelve
115 115
116 116 checks to make sure we dont create a directory or
117 117 hidden file while choosing a new shelve name
118 118
119 119 when we are given a name
120 120
121 121 $ hg shelve -n foo/bar
122 122 abort: shelved change names can not contain slashes
123 123 [255]
124 124 $ hg shelve -n .baz
125 125 abort: shelved change names can not start with '.'
126 126 [255]
127 127 $ hg shelve -n foo\\bar
128 128 abort: shelved change names can not contain slashes
129 129 [255]
130 130
131 131 when shelve has to choose itself
132 132
133 133 $ hg branch x/y -q
134 134 $ hg commit -q -m "Branch commit 0"
135 135 $ hg shelve
136 136 nothing changed
137 137 [1]
138 138 $ hg branch .x -q
139 139 $ hg commit -q -m "Branch commit 1"
140 140 $ hg shelve
141 141 nothing changed
142 142 [1]
143 143 $ hg branch x\\y -q
144 144 $ hg commit -q -m "Branch commit 2"
145 145 $ hg shelve
146 146 nothing changed
147 147 [1]
148 148
149 149 cleaning the branches made for name checking tests
150 150
151 151 $ hg up default -q
152 152 $ hg strip e9177275307e+6a6d231f43d+882bae7c62c2 -q
153 153
154 154 create an mq patch - shelving should work fine with a patch applied
155 155
156 156 $ echo n > n
157 157 $ hg add n
158 158 $ hg commit n -m second
159 159 $ hg qnew second.patch
160 160
161 161 shelve a change that we will delete later
162 162
163 163 $ echo a >> a/a
164 164 $ hg shelve
165 165 shelved as default
166 166 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
167 167
168 168 set up some more complex changes to shelve
169 169
170 170 $ echo a >> a/a
171 171 $ hg mv b b.rename
172 172 moving b/b to b.rename/b
173 173 $ hg cp c c.copy
174 174 $ hg mv d ghost
175 175 $ rm ghost
176 176 $ hg status -C
177 177 M a/a
178 178 A b.rename/b
179 179 b/b
180 180 A c.copy
181 181 c
182 182 R b/b
183 183 R d
184 184 ! ghost
185 185 d
186 186
187 187 the common case - no options or filenames
188 188
189 189 $ hg shelve
190 190 shelved as default-01
191 191 3 files updated, 0 files merged, 2 files removed, 0 files unresolved
192 192 $ hg status -C
193 193
194 194 ensure that our shelved changes exist
195 195
196 196 $ hg shelve -l
197 197 default-01 (*)* changes to: [mq]: second.patch (glob)
198 198 default (*)* changes to: [mq]: second.patch (glob)
199 199
200 200 $ hg shelve -l -p default
201 201 default (*)* changes to: [mq]: second.patch (glob)
202 202
203 203 diff --git a/a/a b/a/a
204 204 --- a/a/a
205 205 +++ b/a/a
206 206 @@ -1,1 +1,2 @@
207 207 a
208 208 +a
209 209
210 210 $ hg shelve --list --addremove
211 211 abort: options '--list' and '--addremove' may not be used together
212 212 [10]
213 213
214 214 delete our older shelved change
215 215
216 216 $ hg shelve -d default
217 217 $ hg qfinish -a -q
218 218
219 219 ensure shelve backups aren't overwritten
220 220
221 221 $ ls .hg/shelve-backup/
222 222 default-1.hg
223 223 default-1.patch
224 224 default-1.shelve
225 225 default.hg
226 226 default.patch
227 227 default.shelve
228 228
229 229 local edits should not prevent a shelved change from applying
230 230
231 231 $ printf "z\na\n" > a/a
232 232 $ hg unshelve --keep
233 233 unshelving change 'default-01'
234 234 temporarily committing pending changes (restore with 'hg unshelve --abort')
235 235 rebasing shelved changes
236 236 merging a/a
237 237
238 238 $ hg revert --all -q
239 239 $ rm a/a.orig b.rename/b c.copy
240 240
241 241 apply it and make sure our state is as expected
242 242
243 243 (this also tests that same timestamp prevents backups from being
244 244 removed, even though there are more than 'maxbackups' backups)
245 245
246 $ f -t .hg/shelve-backup/default.patch
247 .hg/shelve-backup/default.patch: file
248 $ touch -t 200001010000 .hg/shelve-backup/default.patch
249 $ f -t .hg/shelve-backup/default-1.patch
250 .hg/shelve-backup/default-1.patch: file
251 $ touch -t 200001010000 .hg/shelve-backup/default-1.patch
246 $ f -t .hg/shelve-backup/default.shelve
247 .hg/shelve-backup/default.shelve: file
248 $ touch -t 200001010000 .hg/shelve-backup/default.shelve
249 $ f -t .hg/shelve-backup/default-1.shelve
250 .hg/shelve-backup/default-1.shelve: file
251 $ touch -t 200001010000 .hg/shelve-backup/default-1.shelve
252 252
253 253 $ hg unshelve
254 254 unshelving change 'default-01'
255 255 $ hg status -C
256 256 M a/a
257 257 A b.rename/b
258 258 b/b
259 259 A c.copy
260 260 c
261 261 R b/b
262 262 R d
263 263 $ hg shelve -l
264 264
265 265 (both of default.hg and default-1.hg should be still kept, because it
266 266 is difficult to decide actual order of them from same timestamp)
267 267
268 268 $ ls .hg/shelve-backup/
269 269 default-01.hg
270 270 default-01.patch
271 271 default-01.shelve
272 272 default-1.hg
273 273 default-1.patch
274 274 default-1.shelve
275 275 default.hg
276 276 default.patch
277 277 default.shelve
278 278
279 279 $ hg unshelve
280 280 abort: no shelved changes to apply!
281 281 [20]
282 282 $ hg unshelve foo
283 283 abort: shelved change 'foo' not found
284 284 [10]
285 285
286 286 named shelves, specific filenames, and "commit messages" should all work
287 287 (this tests also that editor is invoked, if '--edit' is specified)
288 288
289 289 $ hg status -C
290 290 M a/a
291 291 A b.rename/b
292 292 b/b
293 293 A c.copy
294 294 c
295 295 R b/b
296 296 R d
297 297 $ HGEDITOR=cat hg shelve -q -n wibble -m wat -e a
298 298 wat
299 299
300 300
301 301 HG: Enter commit message. Lines beginning with 'HG:' are removed.
302 302 HG: Leave message empty to abort commit.
303 303 HG: --
304 304 HG: user: shelve@localhost
305 305 HG: branch 'default'
306 306 HG: changed a/a
307 307
308 308 expect "a" to no longer be present, but status otherwise unchanged
309 309
310 310 $ hg status -C
311 311 A b.rename/b
312 312 b/b
313 313 A c.copy
314 314 c
315 315 R b/b
316 316 R d
317 317 $ hg shelve -l --stat
318 318 wibble (*) wat (glob)
319 319 a/a | 1 +
320 320 1 files changed, 1 insertions(+), 0 deletions(-)
321 321
322 322 and now "a/a" should reappear
323 323
324 324 $ cd a
325 325 $ hg unshelve -q wibble
326 326 $ cd ..
327 327 $ hg status -C
328 328 M a/a
329 329 A b.rename/b
330 330 b/b
331 331 A c.copy
332 332 c
333 333 R b/b
334 334 R d
335 335
336 336 ensure old shelve backups are being deleted automatically
337 337
338 338 $ ls .hg/shelve-backup/
339 339 default-01.hg
340 340 default-01.patch
341 341 default-01.shelve
342 342 wibble.hg
343 343 wibble.patch
344 344 wibble.shelve
345 345
346 346 cause unshelving to result in a merge with 'a' conflicting
347 347
348 348 $ hg shelve -q
349 349 $ echo c>>a/a
350 350 $ hg commit -m second
351 351 $ hg tip --template '{files}\n'
352 352 a/a
353 353
354 354 add an unrelated change that should be preserved
355 355
356 356 $ mkdir foo
357 357 $ echo foo > foo/foo
358 358 $ hg add foo/foo
359 359
360 360 force a conflicted merge to occur
361 361
362 362 $ hg unshelve
363 363 unshelving change 'default'
364 364 temporarily committing pending changes (restore with 'hg unshelve --abort')
365 365 rebasing shelved changes
366 366 merging a/a
367 367 warning: conflicts while merging a/a! (edit, then use 'hg resolve --mark')
368 368 unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
369 369 [240]
370 370 $ hg status -v
371 371 M a/a
372 372 M b.rename/b
373 373 M c.copy
374 374 R b/b
375 375 R d
376 376 ? a/a.orig
377 377 # The repository is in an unfinished *unshelve* state.
378 378
379 379 # Unresolved merge conflicts:
380 380 #
381 381 # a/a
382 382 #
383 383 # To mark files as resolved: hg resolve --mark FILE
384 384
385 385 # To continue: hg unshelve --continue
386 386 # To abort: hg unshelve --abort
387 387
388 388
389 389 ensure that we have a merge with unresolved conflicts
390 390
391 391 #if phasebased
392 392 $ hg heads -q --template '{rev}\n'
393 393 8
394 394 5
395 395 $ hg parents -q --template '{rev}\n'
396 396 8
397 397 5
398 398 #endif
399 399
400 400 #if stripbased
401 401 $ hg heads -q --template '{rev}\n'
402 402 5
403 403 4
404 404 $ hg parents -q --template '{rev}\n'
405 405 4
406 406 5
407 407 #endif
408 408
409 409 $ hg status
410 410 M a/a
411 411 M b.rename/b
412 412 M c.copy
413 413 R b/b
414 414 R d
415 415 ? a/a.orig
416 416 $ hg diff
417 417 diff --git a/a/a b/a/a
418 418 --- a/a/a
419 419 +++ b/a/a
420 420 @@ -1,2 +1,6 @@
421 421 a
422 422 +<<<<<<< working-copy: 2377350b6337 - shelve: pending changes temporary commit
423 423 c
424 424 +=======
425 425 +a
426 426 +>>>>>>> shelved change: 203c9f771d2b - shelve: changes to: [mq]: second.patch
427 427 diff --git a/b/b b/b.rename/b
428 428 rename from b/b
429 429 rename to b.rename/b
430 430 diff --git a/c b/c.copy
431 431 copy from c
432 432 copy to c.copy
433 433 diff --git a/d b/d
434 434 deleted file mode 100644
435 435 --- a/d
436 436 +++ /dev/null
437 437 @@ -1,1 +0,0 @@
438 438 -d
439 439 $ hg resolve -l
440 440 U a/a
441 441
442 442 $ hg shelve
443 443 abort: unshelve already in progress
444 444 (use 'hg unshelve --continue' or 'hg unshelve --abort')
445 445 [20]
446 446
447 447 abort the unshelve and be happy
448 448
449 449 $ hg status
450 450 M a/a
451 451 M b.rename/b
452 452 M c.copy
453 453 R b/b
454 454 R d
455 455 ? a/a.orig
456 456 $ hg unshelve -a
457 457 unshelve of 'default' aborted
458 458 $ hg heads -q
459 459 [37]:2e69b451d1ea (re)
460 460 $ hg parents
461 461 changeset: [37]:2e69b451d1ea (re)
462 462 tag: tip
463 463 parent: 3:509104101065 (?)
464 464 user: test
465 465 date: Thu Jan 01 00:00:00 1970 +0000
466 466 summary: second
467 467
468 468 $ hg resolve -l
469 469 $ hg status
470 470 A foo/foo
471 471 ? a/a.orig
472 472
473 473 try to continue with no unshelve underway
474 474
475 475 $ hg unshelve -c
476 476 abort: no unshelve in progress
477 477 [20]
478 478 $ hg status
479 479 A foo/foo
480 480 ? a/a.orig
481 481
482 482 redo the unshelve to get a conflict
483 483
484 484 $ hg unshelve -q
485 485 warning: conflicts while merging a/a! (edit, then use 'hg resolve --mark')
486 486 unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
487 487 [240]
488 488
489 489 attempt to continue
490 490
491 491 $ hg unshelve -c
492 492 abort: unresolved conflicts, can't continue
493 493 (see 'hg resolve', then 'hg unshelve --continue')
494 494 [255]
495 495
496 496 $ hg revert -r . a/a
497 497 $ hg resolve -m a/a
498 498 (no more unresolved files)
499 499 continue: hg unshelve --continue
500 500
501 501 $ hg commit -m 'commit while unshelve in progress'
502 502 abort: unshelve already in progress
503 503 (use 'hg unshelve --continue' or 'hg unshelve --abort')
504 504 [20]
505 505
506 506 $ hg graft --continue
507 507 abort: no graft in progress
508 508 (continue: hg unshelve --continue)
509 509 [20]
510 510 $ hg unshelve -c
511 511 unshelve of 'default' complete
512 512
513 513 ensure the repo is as we hope
514 514
515 515 $ hg parents
516 516 changeset: [37]:2e69b451d1ea (re)
517 517 tag: tip
518 518 parent: 3:509104101065 (?)
519 519 user: test
520 520 date: Thu Jan 01 00:00:00 1970 +0000
521 521 summary: second
522 522
523 523 $ hg heads -q
524 524 [37]:2e69b451d1ea (re)
525 525
526 526 $ hg status -C
527 527 A b.rename/b
528 528 b/b
529 529 A c.copy
530 530 c
531 531 A foo/foo
532 532 R b/b
533 533 R d
534 534 ? a/a.orig
535 535
536 536 there should be no shelves left
537 537
538 538 $ hg shelve -l
539 539
540 540 #if execbit
541 541
542 542 ensure that metadata-only changes are shelved
543 543
544 544 $ chmod +x a/a
545 545 $ hg shelve -q -n execbit a/a
546 546 $ hg status a/a
547 547 $ hg unshelve -q execbit
548 548 $ hg status a/a
549 549 M a/a
550 550 $ hg revert a/a
551 551
552 552 #else
553 553
554 554 Dummy shelve op, to keep rev numbers aligned
555 555
556 556 $ echo foo > a/a
557 557 $ hg shelve -q -n dummy a/a
558 558 $ hg unshelve -q dummy
559 559 $ hg revert a/a
560 560
561 561 #endif
562 562
563 563 #if symlink
564 564
565 565 $ rm a/a
566 566 $ ln -s foo a/a
567 567 $ hg shelve -q -n symlink a/a
568 568 $ hg status a/a
569 569 $ hg unshelve -q -n symlink
570 570 $ hg status a/a
571 571 M a/a
572 572 $ hg revert a/a
573 573
574 574 #else
575 575
576 576 Dummy shelve op, to keep rev numbers aligned
577 577
578 578 $ echo bar > a/a
579 579 $ hg shelve -q -n dummy a/a
580 580 $ hg unshelve -q dummy
581 581 $ hg revert a/a
582 582
583 583 #endif
584 584
585 585 set up another conflict between a commit and a shelved change
586 586
587 587 $ hg revert -q -C -a
588 588 $ rm a/a.orig b.rename/b c.copy
589 589 $ echo a >> a/a
590 590 $ hg shelve -q
591 591 $ echo x >> a/a
592 592 $ hg ci -m 'create conflict'
593 593 $ hg add foo/foo
594 594
595 595 if we resolve a conflict while unshelving, the unshelve should succeed
596 596
597 597 $ hg unshelve --tool :merge-other --keep
598 598 unshelving change 'default'
599 599 temporarily committing pending changes (restore with 'hg unshelve --abort')
600 600 rebasing shelved changes
601 601 merging a/a
602 602 $ hg parents -q
603 603 (4|13):33f7f61e6c5e (re)
604 604 $ hg shelve -l
605 605 default (*)* changes to: second (glob)
606 606 $ hg status
607 607 M a/a
608 608 A foo/foo
609 609 $ cat a/a
610 610 a
611 611 c
612 612 a
613 613 $ cat > a/a << EOF
614 614 > a
615 615 > c
616 616 > x
617 617 > EOF
618 618
619 619 $ HGMERGE=true hg unshelve
620 620 unshelving change 'default'
621 621 temporarily committing pending changes (restore with 'hg unshelve --abort')
622 622 rebasing shelved changes
623 623 merging a/a
624 624 note: unshelved changes already existed in the working copy
625 625 $ hg parents -q
626 626 (4|13):33f7f61e6c5e (re)
627 627 $ hg shelve -l
628 628 $ hg status
629 629 A foo/foo
630 630 $ cat a/a
631 631 a
632 632 c
633 633 x
634 634
635 635 test keep and cleanup
636 636
637 637 $ hg shelve
638 638 shelved as default
639 639 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
640 640 $ hg shelve --list
641 641 default (*)* changes to: create conflict (glob)
642 642 $ hg unshelve -k
643 643 unshelving change 'default'
644 644 $ hg shelve --list
645 645 default (*)* changes to: create conflict (glob)
646 646 $ hg shelve --cleanup
647 647 $ hg shelve --list
648 648
649 649 $ hg shelve --cleanup --delete
650 650 abort: options '--cleanup' and '--delete' may not be used together
651 651 [10]
652 652 $ hg shelve --cleanup --patch
653 653 abort: options '--cleanup' and '--patch' may not be used together
654 654 [10]
655 655 $ hg shelve --cleanup --message MESSAGE
656 656 abort: options '--cleanup' and '--message' may not be used together
657 657 [10]
658 658
659 659 test bookmarks
660 660
661 661 $ hg bookmark test
662 662 $ hg bookmark
663 663 \* test (4|13):33f7f61e6c5e (re)
664 664 $ hg shelve
665 665 shelved as test
666 666 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
667 667 $ hg bookmark
668 668 \* test (4|13):33f7f61e6c5e (re)
669 669 $ hg unshelve
670 670 unshelving change 'test'
671 671 $ hg bookmark
672 672 \* test (4|13):33f7f61e6c5e (re)
673 673
674 674 shelve should still work even if mq is disabled
675 675
676 676 $ hg --config extensions.mq=! shelve
677 677 shelved as test
678 678 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
679 679 $ hg --config extensions.mq=! shelve --list
680 680 test (*)* changes to: create conflict (glob)
681 681 $ hg bookmark
682 682 \* test (4|13):33f7f61e6c5e (re)
683 683 $ hg --config extensions.mq=! unshelve
684 684 unshelving change 'test'
685 685 $ hg bookmark
686 686 \* test (4|13):33f7f61e6c5e (re)
687 687
688 688 Recreate some conflict again
689 689
690 690 $ hg up -C -r 2e69b451d1ea
691 691 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
692 692 (leaving bookmark test)
693 693 $ echo y >> a/a
694 694 $ hg shelve
695 695 shelved as default
696 696 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
697 697 $ hg up test
698 698 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
699 699 (activating bookmark test)
700 700 $ hg bookmark
701 701 \* test (4|13):33f7f61e6c5e (re)
702 702 $ hg unshelve
703 703 unshelving change 'default'
704 704 rebasing shelved changes
705 705 merging a/a
706 706 warning: conflicts while merging a/a! (edit, then use 'hg resolve --mark')
707 707 unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
708 708 [240]
709 709 $ hg bookmark
710 710 test (4|13):33f7f61e6c5e (re)
711 711
712 712 Test that resolving all conflicts in one direction (so that the rebase
713 713 is a no-op), works (issue4398)
714 714
715 715 $ hg revert -a -r .
716 716 reverting a/a
717 717 $ hg resolve -m a/a
718 718 (no more unresolved files)
719 719 continue: hg unshelve --continue
720 720 $ hg unshelve -c
721 721 note: unshelved changes already existed in the working copy
722 722 unshelve of 'default' complete
723 723 $ hg bookmark
724 724 \* test (4|13):33f7f61e6c5e (re)
725 725 $ hg diff
726 726 $ hg status
727 727 ? a/a.orig
728 728 ? foo/foo
729 729 $ hg summary
730 730 parent: (4|13):33f7f61e6c5e tip (re)
731 731 create conflict
732 732 branch: default
733 733 bookmarks: *test
734 734 commit: 2 unknown (clean)
735 735 update: (current)
736 736 phases: 5 draft
737 737
738 738 $ hg shelve --delete --stat
739 739 abort: options '--delete' and '--stat' may not be used together
740 740 [10]
741 741 $ hg shelve --delete --name NAME
742 742 abort: options '--delete' and '--name' may not be used together
743 743 [10]
744 744
745 745 Test interactive shelve
746 746 $ cat <<EOF >> $HGRCPATH
747 747 > [ui]
748 748 > interactive = true
749 749 > EOF
750 750 $ echo 'a' >> a/b
751 751 $ cat a/a >> a/b
752 752 $ echo 'x' >> a/b
753 753 $ mv a/b a/a
754 754 $ echo 'a' >> foo/foo
755 755 $ hg st
756 756 M a/a
757 757 ? a/a.orig
758 758 ? foo/foo
759 759 $ cat a/a
760 760 a
761 761 a
762 762 c
763 763 x
764 764 x
765 765 $ cat foo/foo
766 766 foo
767 767 a
768 768 $ hg shelve --interactive --config ui.interactive=false
769 769 abort: running non-interactively
770 770 [10]
771 771 $ hg shelve --interactive << EOF
772 772 > y
773 773 > y
774 774 > n
775 775 > EOF
776 776 diff --git a/a/a b/a/a
777 777 2 hunks, 2 lines changed
778 778 examine changes to 'a/a'?
779 779 (enter ? for help) [Ynesfdaq?] y
780 780
781 781 @@ -1,3 +1,4 @@
782 782 +a
783 783 a
784 784 c
785 785 x
786 786 record change 1/2 to 'a/a'?
787 787 (enter ? for help) [Ynesfdaq?] y
788 788
789 789 @@ -1,3 +2,4 @@
790 790 a
791 791 c
792 792 x
793 793 +x
794 794 record change 2/2 to 'a/a'?
795 795 (enter ? for help) [Ynesfdaq?] n
796 796
797 797 shelved as test
798 798 merging a/a
799 799 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
800 800 $ cat a/a
801 801 a
802 802 c
803 803 x
804 804 x
805 805 $ cat foo/foo
806 806 foo
807 807 a
808 808 $ hg st
809 809 M a/a
810 810 ? foo/foo
811 811 $ hg bookmark
812 812 \* test (4|13):33f7f61e6c5e (re)
813 813 there shouldn't be a merge state
814 814 $ hg resolve -l
815 815 $ hg unshelve
816 816 unshelving change 'test'
817 817 temporarily committing pending changes (restore with 'hg unshelve --abort')
818 818 rebasing shelved changes
819 819 merging a/a
820 820 $ hg bookmark
821 821 \* test (4|13):33f7f61e6c5e (re)
822 822 $ cat a/a
823 823 a
824 824 a
825 825 c
826 826 x
827 827 x
828 828
829 829 shelve --patch and shelve --stat should work with valid shelfnames
830 830
831 831 $ hg up --clean .
832 832 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
833 833 (leaving bookmark test)
834 834 $ hg shelve --list
835 835 $ echo 'patch a' > shelf-patch-a
836 836 $ hg add shelf-patch-a
837 837 $ hg shelve
838 838 shelved as default
839 839 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
840 840 $ echo 'patch b' > shelf-patch-b
841 841 $ hg add shelf-patch-b
842 842 $ hg shelve
843 843 shelved as default-01
844 844 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
845 845 $ hg shelve --patch default default-01
846 846 default-01 (*)* changes to: create conflict (glob)
847 847
848 848 diff --git a/shelf-patch-b b/shelf-patch-b
849 849 new file mode 100644
850 850 --- /dev/null
851 851 +++ b/shelf-patch-b
852 852 @@ -0,0 +1,1 @@
853 853 +patch b
854 854 default (*)* changes to: create conflict (glob)
855 855
856 856 diff --git a/shelf-patch-a b/shelf-patch-a
857 857 new file mode 100644
858 858 --- /dev/null
859 859 +++ b/shelf-patch-a
860 860 @@ -0,0 +1,1 @@
861 861 +patch a
862 862 $ hg shelve --stat default default-01
863 863 default-01 (*)* changes to: create conflict (glob)
864 864 shelf-patch-b | 1 +
865 865 1 files changed, 1 insertions(+), 0 deletions(-)
866 866 default (*)* changes to: create conflict (glob)
867 867 shelf-patch-a | 1 +
868 868 1 files changed, 1 insertions(+), 0 deletions(-)
869 869 $ hg shelve --patch default
870 870 default (*)* changes to: create conflict (glob)
871 871
872 872 diff --git a/shelf-patch-a b/shelf-patch-a
873 873 new file mode 100644
874 874 --- /dev/null
875 875 +++ b/shelf-patch-a
876 876 @@ -0,0 +1,1 @@
877 877 +patch a
878 878 $ hg shelve --stat default
879 879 default (*)* changes to: create conflict (glob)
880 880 shelf-patch-a | 1 +
881 881 1 files changed, 1 insertions(+), 0 deletions(-)
882 882 $ hg shelve --patch nonexistentshelf
883 883 abort: cannot find shelf nonexistentshelf
884 884 [255]
885 885 $ hg shelve --stat nonexistentshelf
886 886 abort: cannot find shelf nonexistentshelf
887 887 [255]
888 888 $ hg shelve --patch default nonexistentshelf
889 889 abort: cannot find shelf nonexistentshelf
890 890 [255]
891 891
892 892 when the user asks for a patch, we assume they want the most recent shelve if
893 893 they don't provide a shelve name
894 894
895 895 $ hg shelve --patch
896 896 default-01 (*)* changes to: create conflict (glob)
897 897
898 898 diff --git a/shelf-patch-b b/shelf-patch-b
899 899 new file mode 100644
900 900 --- /dev/null
901 901 +++ b/shelf-patch-b
902 902 @@ -0,0 +1,1 @@
903 903 +patch b
904 904
905 905 $ cd ..
906 906
907 907 Shelve from general delta repo uses bundle2 on disk
908 908 --------------------------------------------------
909 909
910 910 no general delta
911 911
912 912 $ hg clone --pull repo bundle1 --config format.usegeneraldelta=0
913 913 requesting all changes
914 914 adding changesets
915 915 adding manifests
916 916 adding file changes
917 917 added 5 changesets with 8 changes to 6 files
918 918 new changesets cc01e2b0c59f:33f7f61e6c5e
919 919 updating to branch default
920 920 6 files updated, 0 files merged, 0 files removed, 0 files unresolved
921 921 $ cd bundle1
922 922 $ echo babar > jungle
923 923 $ hg add jungle
924 924 $ hg shelve
925 925 shelved as default
926 926 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
927 927 $ hg debugbundle .hg/shelved/*.hg
928 928 330882a04d2ce8487636b1fb292e5beea77fa1e3
929 929 $ cd ..
930 930
931 931 with general delta
932 932
933 933 $ hg clone --pull repo bundle2 --config format.usegeneraldelta=1
934 934 requesting all changes
935 935 adding changesets
936 936 adding manifests
937 937 adding file changes
938 938 added 5 changesets with 8 changes to 6 files
939 939 new changesets cc01e2b0c59f:33f7f61e6c5e
940 940 updating to branch default
941 941 6 files updated, 0 files merged, 0 files removed, 0 files unresolved
942 942 $ cd bundle2
943 943 $ echo babar > jungle
944 944 $ hg add jungle
945 945 $ hg shelve
946 946 shelved as default
947 947 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
948 948 $ hg debugbundle .hg/shelved/*.hg
949 949 Stream params: {Compression: BZ}
950 950 changegroup -- {nbchanges: 1, version: 02} (mandatory: True)
951 951 330882a04d2ce8487636b1fb292e5beea77fa1e3
952 952
953 953 Test shelve --keep
954 954
955 955 $ hg unshelve
956 956 unshelving change 'default'
957 957 $ hg shelve --keep --list
958 958 abort: options '--list' and '--keep' may not be used together
959 959 [10]
960 960 $ hg shelve --keep --patch
961 961 abort: options '--patch' and '--keep' may not be used together
962 962 [10]
963 963 $ hg shelve --keep --delete
964 964 abort: options '--delete' and '--keep' may not be used together
965 965 [10]
966 966 $ hg shelve --keep
967 967 shelved as default
968 968 $ hg diff
969 969 diff --git a/jungle b/jungle
970 970 new file mode 100644
971 971 --- /dev/null
972 972 +++ b/jungle
973 973 @@ -0,0 +1,1 @@
974 974 +babar
975 975
976 976 Test shelve --delete
977 977
978 978 $ hg shelve --list
979 979 default (*s ago) * changes to: create conflict (glob)
980 980 $ hg shelve --delete doesnotexist
981 981 abort: shelved change 'doesnotexist' not found
982 982 [10]
983 983 $ hg shelve --delete default
984 984
985 985 $ cd ..
986 986
987 987 Test visibility of in-memory changes inside transaction to external hook
988 988 ------------------------------------------------------------------------
989 989
990 990 $ cd repo
991 991
992 992 $ echo xxxx >> x
993 993 $ hg commit -m "#5: changes to invoke rebase"
994 994
995 995 $ cat > $TESTTMP/checkvisibility.sh <<EOF
996 996 > echo "==== \$1:"
997 997 > hg parents --template "VISIBLE {rev}:{node|short}\n"
998 998 > # test that pending changes are hidden
999 999 > unset HG_PENDING
1000 1000 > hg parents --template "ACTUAL {rev}:{node|short}\n"
1001 1001 > echo "===="
1002 1002 > EOF
1003 1003
1004 1004 $ cat >> .hg/hgrc <<EOF
1005 1005 > [defaults]
1006 1006 > # to fix hash id of temporary revisions
1007 1007 > unshelve = --date '0 0'
1008 1008 > EOF
1009 1009
1010 1010 "hg unshelve" at REV5 implies steps below:
1011 1011
1012 1012 (1) commit changes in the working directory (REV6)
1013 1013 (2) unbundle shelved revision (REV7)
1014 1014 (3) rebase: merge REV7 into REV6 (REV6 => REV6, REV7)
1015 1015 (4) rebase: commit merged revision (REV8)
1016 1016 (5) rebase: update to REV6 (REV8 => REV6)
1017 1017 (6) update to REV5 (REV6 => REV5)
1018 1018 (7) abort transaction
1019 1019
1020 1020 == test visibility to external preupdate hook
1021 1021
1022 1022 $ cat >> .hg/hgrc <<EOF
1023 1023 > [hooks]
1024 1024 > preupdate.visibility = sh $TESTTMP/checkvisibility.sh preupdate
1025 1025 > EOF
1026 1026
1027 1027 $ echo nnnn >> n
1028 1028
1029 1029 $ sh $TESTTMP/checkvisibility.sh before-unshelving
1030 1030 ==== before-unshelving:
1031 1031 VISIBLE (5|19):703117a2acfb (re)
1032 1032 ACTUAL (5|19):703117a2acfb (re)
1033 1033 ====
1034 1034
1035 1035 $ hg unshelve --keep default
1036 1036 temporarily committing pending changes (restore with 'hg unshelve --abort')
1037 1037 rebasing shelved changes
1038 1038 ==== preupdate:
1039 1039 VISIBLE (6|20):54c00d20fb3f (re)
1040 1040 ACTUAL (5|19):703117a2acfb (re)
1041 1041 ====
1042 1042 ==== preupdate:
1043 1043 VISIBLE (8|21):8efe6f7537dc (re)
1044 1044 ACTUAL (5|19):703117a2acfb (re)
1045 1045 ====
1046 1046 ==== preupdate:
1047 1047 VISIBLE (6|20):54c00d20fb3f (re)
1048 1048 ACTUAL (5|19):703117a2acfb (re)
1049 1049 ====
1050 1050
1051 1051 $ cat >> .hg/hgrc <<EOF
1052 1052 > [hooks]
1053 1053 > preupdate.visibility =
1054 1054 > EOF
1055 1055
1056 1056 $ sh $TESTTMP/checkvisibility.sh after-unshelving
1057 1057 ==== after-unshelving:
1058 1058 VISIBLE (5|19):703117a2acfb (re)
1059 1059 ACTUAL (5|19):703117a2acfb (re)
1060 1060 ====
1061 1061
1062 1062 == test visibility to external update hook
1063 1063
1064 1064 $ hg update -q -C 703117a2acfb
1065 1065
1066 1066 $ cat >> .hg/hgrc <<EOF
1067 1067 > [hooks]
1068 1068 > update.visibility = sh $TESTTMP/checkvisibility.sh update
1069 1069 > EOF
1070 1070
1071 1071 $ echo nnnn >> n
1072 1072
1073 1073 $ sh $TESTTMP/checkvisibility.sh before-unshelving
1074 1074 ==== before-unshelving:
1075 1075 VISIBLE (5|19):703117a2acfb (re)
1076 1076 ACTUAL (5|19):703117a2acfb (re)
1077 1077 ====
1078 1078
1079 1079 $ hg unshelve --keep default
1080 1080 temporarily committing pending changes (restore with 'hg unshelve --abort')
1081 1081 rebasing shelved changes
1082 1082 ==== update:
1083 1083 VISIBLE (6|20):54c00d20fb3f (re)
1084 1084 VISIBLE 1?7:492ed9d705e5 (re)
1085 1085 ACTUAL (5|19):703117a2acfb (re)
1086 1086 ====
1087 1087 ==== update:
1088 1088 VISIBLE (6|20):54c00d20fb3f (re)
1089 1089 ACTUAL (5|19):703117a2acfb (re)
1090 1090 ====
1091 1091 ==== update:
1092 1092 VISIBLE (5|19):703117a2acfb (re)
1093 1093 ACTUAL (5|19):703117a2acfb (re)
1094 1094 ====
1095 1095
1096 1096 $ cat >> .hg/hgrc <<EOF
1097 1097 > [hooks]
1098 1098 > update.visibility =
1099 1099 > EOF
1100 1100
1101 1101 $ sh $TESTTMP/checkvisibility.sh after-unshelving
1102 1102 ==== after-unshelving:
1103 1103 VISIBLE (5|19):703117a2acfb (re)
1104 1104 ACTUAL (5|19):703117a2acfb (re)
1105 1105 ====
1106 1106
1107 1107 $ cd ..
1108 1108
1109 1109 Keep active bookmark while (un)shelving even on shared repo (issue4940)
1110 1110 -----------------------------------------------------------------------
1111 1111
1112 1112 $ cat <<EOF >> $HGRCPATH
1113 1113 > [extensions]
1114 1114 > share =
1115 1115 > EOF
1116 1116
1117 1117 $ hg bookmarks -R repo
1118 1118 test (4|13):33f7f61e6c5e (re)
1119 1119 $ hg share -B repo share
1120 1120 updating working directory
1121 1121 6 files updated, 0 files merged, 0 files removed, 0 files unresolved
1122 1122 $ cd share
1123 1123
1124 1124 $ hg bookmarks
1125 1125 test (4|13):33f7f61e6c5e (re)
1126 1126 $ hg bookmarks foo
1127 1127 $ hg bookmarks
1128 1128 \* foo (5|19):703117a2acfb (re)
1129 1129 test (4|13):33f7f61e6c5e (re)
1130 1130 $ echo x >> x
1131 1131 $ hg shelve
1132 1132 shelved as foo
1133 1133 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1134 1134 $ hg bookmarks
1135 1135 \* foo (5|19):703117a2acfb (re)
1136 1136 test (4|13):33f7f61e6c5e (re)
1137 1137
1138 1138 $ hg unshelve
1139 1139 unshelving change 'foo'
1140 1140 $ hg bookmarks
1141 1141 \* foo (5|19):703117a2acfb (re)
1142 1142 test (4|13):33f7f61e6c5e (re)
1143 1143
1144 1144 $ cd ..
1145 1145
1146 1146 Abort unshelve while merging (issue5123)
1147 1147 ----------------------------------------
1148 1148
1149 1149 $ hg init issue5123
1150 1150 $ cd issue5123
1151 1151 $ echo > a
1152 1152 $ hg ci -Am a
1153 1153 adding a
1154 1154 $ hg co null
1155 1155 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1156 1156 $ echo > b
1157 1157 $ hg ci -Am b
1158 1158 adding b
1159 1159 created new head
1160 1160 $ echo > c
1161 1161 $ hg add c
1162 1162 $ hg shelve
1163 1163 shelved as default
1164 1164 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1165 1165 $ hg co 1
1166 1166 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1167 1167 $ hg merge 0
1168 1168 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1169 1169 (branch merge, don't forget to commit)
1170 1170 -- successful merge with two parents
1171 1171 $ hg log -G
1172 1172 @ changeset: 1:406bf70c274f
1173 1173 tag: tip
1174 1174 parent: -1:000000000000
1175 1175 user: test
1176 1176 date: Thu Jan 01 00:00:00 1970 +0000
1177 1177 summary: b
1178 1178
1179 1179 @ changeset: 0:ada8c9eb8252
1180 1180 user: test
1181 1181 date: Thu Jan 01 00:00:00 1970 +0000
1182 1182 summary: a
1183 1183
1184 1184 -- trying to pull in the shelve bits
1185 1185 -- unshelve should abort otherwise, it'll eat my second parent.
1186 1186 $ hg unshelve
1187 1187 abort: outstanding uncommitted merge
1188 1188 (use 'hg commit' or 'hg merge --abort')
1189 1189 [20]
1190 1190
1191 1191 $ cd ..
1192 1192
1193 1193 -- test for interactive mode on unshelve
1194 1194
1195 1195 $ hg init a
1196 1196 $ cd a
1197 1197 $ echo > b
1198 1198 $ hg ci -Am b
1199 1199 adding b
1200 1200 $ echo > c
1201 1201 $ echo > d
1202 1202 $ hg add .
1203 1203 adding c
1204 1204 adding d
1205 1205 $ hg shelve
1206 1206 shelved as default
1207 1207 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
1208 1208 $ echo > e
1209 1209 $ hg add e
1210 1210 $ hg ci -m e
1211 1211 $ hg shelve --patch
1212 1212 default (*s ago) * changes to: b (glob)
1213 1213
1214 1214 diff --git a/c b/c
1215 1215 new file mode 100644
1216 1216 --- /dev/null
1217 1217 +++ b/c
1218 1218 @@ -0,0 +1,1 @@
1219 1219 +
1220 1220 diff --git a/d b/d
1221 1221 new file mode 100644
1222 1222 --- /dev/null
1223 1223 +++ b/d
1224 1224 @@ -0,0 +1,1 @@
1225 1225 +
1226 1226 $ hg unshelve -i <<EOF
1227 1227 > y
1228 1228 > y
1229 1229 > y
1230 1230 > n
1231 1231 > EOF
1232 1232 unshelving change 'default'
1233 1233 rebasing shelved changes
1234 1234 diff --git a/c b/c
1235 1235 new file mode 100644
1236 1236 examine changes to 'c'?
1237 1237 (enter ? for help) [Ynesfdaq?] y
1238 1238
1239 1239 @@ -0,0 +1,1 @@
1240 1240 +
1241 1241 record change 1/2 to 'c'?
1242 1242 (enter ? for help) [Ynesfdaq?] y
1243 1243
1244 1244 diff --git a/d b/d
1245 1245 new file mode 100644
1246 1246 examine changes to 'd'?
1247 1247 (enter ? for help) [Ynesfdaq?] y
1248 1248
1249 1249 @@ -0,0 +1,1 @@
1250 1250 +
1251 1251 record change 2/2 to 'd'?
1252 1252 (enter ? for help) [Ynesfdaq?] n
1253 1253
1254 1254 $ ls -A
1255 1255 .hg
1256 1256 b
1257 1257 c
1258 1258 e
1259 1259 -- shelve should not contain `c` now
1260 1260 $ hg shelve --patch
1261 1261 default (*s ago) * changes to: b (glob)
1262 1262
1263 1263 diff --git a/d b/d
1264 1264 new file mode 100644
1265 1265 --- /dev/null
1266 1266 +++ b/d
1267 1267 @@ -0,0 +1,1 @@
1268 1268 +
1269 1269 $ hg unshelve -i <<EOF
1270 1270 > y
1271 1271 > y
1272 1272 > EOF
1273 1273 unshelving change 'default'
1274 1274 temporarily committing pending changes (restore with 'hg unshelve --abort')
1275 1275 rebasing shelved changes
1276 1276 diff --git a/d b/d
1277 1277 new file mode 100644
1278 1278 examine changes to 'd'?
1279 1279 (enter ? for help) [Ynesfdaq?] y
1280 1280
1281 1281 @@ -0,0 +1,1 @@
1282 1282 +
1283 1283 record this change to 'd'?
1284 1284 (enter ? for help) [Ynesfdaq?] y
1285 1285
1286 1286
1287 1287 $ hg status -v
1288 1288 A c
1289 1289 A d
1290 1290 $ ls -A
1291 1291 .hg
1292 1292 b
1293 1293 c
1294 1294 d
1295 1295 e
1296 1296 $ hg shelve --list
1297 1297
1298 1298 -- now, unshelve selected changes from a file
1299 1299
1300 1300 $ echo B > foo
1301 1301 $ hg add foo
1302 1302 $ hg ci -m 'add B to foo'
1303 1303 $ cat > foo <<EOF
1304 1304 > A
1305 1305 > B
1306 1306 > C
1307 1307 > EOF
1308 1308 $ echo > garbage
1309 1309 $ hg st
1310 1310 M foo
1311 1311 ? garbage
1312 1312 $ hg shelve --unknown
1313 1313 shelved as default
1314 1314 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
1315 1315 $ cat foo
1316 1316 B
1317 1317 $ hg unshelve -i <<EOF
1318 1318 > y
1319 1319 > y
1320 1320 > n
1321 1321 > y
1322 1322 > y
1323 1323 > EOF
1324 1324 unshelving change 'default'
1325 1325 rebasing shelved changes
1326 1326 diff --git a/foo b/foo
1327 1327 2 hunks, 2 lines changed
1328 1328 examine changes to 'foo'?
1329 1329 (enter ? for help) [Ynesfdaq?] y
1330 1330
1331 1331 @@ -1,1 +1,2 @@
1332 1332 +A
1333 1333 B
1334 1334 record change 1/3 to 'foo'?
1335 1335 (enter ? for help) [Ynesfdaq?] y
1336 1336
1337 1337 @@ -1,1 +2,2 @@
1338 1338 B
1339 1339 +C
1340 1340 record change 2/3 to 'foo'?
1341 1341 (enter ? for help) [Ynesfdaq?] n
1342 1342
1343 1343 diff --git a/garbage b/garbage
1344 1344 new file mode 100644
1345 1345 examine changes to 'garbage'?
1346 1346 (enter ? for help) [Ynesfdaq?] y
1347 1347
1348 1348 @@ -0,0 +1,1 @@
1349 1349 +
1350 1350 record change 3/3 to 'garbage'?
1351 1351 (enter ? for help) [Ynesfdaq?] y
1352 1352
1353 1353 $ hg st
1354 1354 M foo
1355 1355 ? garbage
1356 1356 $ cat foo
1357 1357 A
1358 1358 B
1359 1359 $ hg shelve --patch
1360 1360 default (*s ago) * changes to: add B to foo (glob)
1361 1361
1362 1362 diff --git a/foo b/foo
1363 1363 --- a/foo
1364 1364 +++ b/foo
1365 1365 @@ -1,2 +1,3 @@
1366 1366 A
1367 1367 B
1368 1368 +C
1369 1369
1370 1370 -- unshelve interactive on conflicts
1371 1371
1372 1372 $ echo A >> bar1
1373 1373 $ echo A >> bar2
1374 1374 $ hg add bar1 bar2
1375 1375 $ hg ci -m 'add A to bars'
1376 1376 $ echo B >> bar1
1377 1377 $ echo B >> bar2
1378 1378 $ hg shelve
1379 1379 shelved as default-01
1380 1380 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
1381 1381 $ echo C >> bar1
1382 1382 $ echo C >> bar2
1383 1383 $ hg ci -m 'add C to bars'
1384 1384 $ hg unshelve -i
1385 1385 unshelving change 'default-01'
1386 1386 rebasing shelved changes
1387 1387 merging bar1
1388 1388 warning: conflicts while merging bar1! (edit, then use 'hg resolve --mark')
1389 1389 merging bar2
1390 1390 warning: conflicts while merging bar2! (edit, then use 'hg resolve --mark')
1391 1391 unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
1392 1392 [240]
1393 1393
1394 1394 $ cat > bar1 <<EOF
1395 1395 > A
1396 1396 > B
1397 1397 > C
1398 1398 > EOF
1399 1399 $ cat > bar2 <<EOF
1400 1400 > A
1401 1401 > B
1402 1402 > C
1403 1403 > EOF
1404 1404 $ hg resolve -m bar1 bar2
1405 1405 (no more unresolved files)
1406 1406 continue: hg unshelve --continue
1407 1407
1408 1408 -- using --continue with --interactive should throw an error
1409 1409 $ hg unshelve --continue -i
1410 1410 abort: cannot use both continue and interactive
1411 1411 [10]
1412 1412
1413 1413 $ cat bar1
1414 1414 A
1415 1415 B
1416 1416 C
1417 1417
1418 1418 #if stripbased
1419 1419 $ hg log -r 3:: -G
1420 1420 @ changeset: 5:f1d5f53e397b
1421 1421 | tag: tip
1422 1422 | parent: 3:e28fd7fa7938
1423 1423 | user: shelve@localhost
1424 1424 | date: Thu Jan 01 00:00:00 1970 +0000
1425 1425 | summary: changes to: add A to bars
1426 1426 |
1427 1427 | @ changeset: 4:fe451a778c81
1428 1428 |/ user: test
1429 1429 | date: Thu Jan 01 00:00:00 1970 +0000
1430 1430 | summary: add C to bars
1431 1431 |
1432 1432 o changeset: 3:e28fd7fa7938
1433 1433 | user: test
1434 1434 ~ date: Thu Jan 01 00:00:00 1970 +0000
1435 1435 summary: add A to bars
1436 1436
1437 1437 #endif
1438 1438
1439 1439 $ hg unshelve --continue <<EOF
1440 1440 > y
1441 1441 > y
1442 1442 > y
1443 1443 > n
1444 1444 > EOF
1445 1445 diff --git a/bar1 b/bar1
1446 1446 1 hunks, 1 lines changed
1447 1447 examine changes to 'bar1'?
1448 1448 (enter ? for help) [Ynesfdaq?] y
1449 1449
1450 1450 @@ -1,2 +1,3 @@
1451 1451 A
1452 1452 +B
1453 1453 C
1454 1454 record change 1/2 to 'bar1'?
1455 1455 (enter ? for help) [Ynesfdaq?] y
1456 1456
1457 1457 diff --git a/bar2 b/bar2
1458 1458 1 hunks, 1 lines changed
1459 1459 examine changes to 'bar2'?
1460 1460 (enter ? for help) [Ynesfdaq?] y
1461 1461
1462 1462 @@ -1,2 +1,3 @@
1463 1463 A
1464 1464 +B
1465 1465 C
1466 1466 record change 2/2 to 'bar2'?
1467 1467 (enter ? for help) [Ynesfdaq?] n
1468 1468
1469 1469 unshelve of 'default-01' complete
1470 1470
1471 1471 #if stripbased
1472 1472 $ hg log -r 3:: -G
1473 1473 @ changeset: 4:fe451a778c81
1474 1474 | tag: tip
1475 1475 | user: test
1476 1476 | date: Thu Jan 01 00:00:00 1970 +0000
1477 1477 | summary: add C to bars
1478 1478 |
1479 1479 o changeset: 3:e28fd7fa7938
1480 1480 | user: test
1481 1481 ~ date: Thu Jan 01 00:00:00 1970 +0000
1482 1482 summary: add A to bars
1483 1483
1484 1484 #endif
1485 1485
1486 1486 $ hg unshelve --continue
1487 1487 abort: no unshelve in progress
1488 1488 [20]
1489 1489
1490 1490 $ hg shelve --list
1491 1491 default-01 (*)* changes to: add A to bars (glob)
1492 1492 default (*)* changes to: add B to foo (glob)
1493 1493 $ hg unshelve -n default-01 -i <<EOF
1494 1494 > y
1495 1495 > y
1496 1496 > EOF
1497 1497 temporarily committing pending changes (restore with 'hg unshelve --abort')
1498 1498 rebasing shelved changes
1499 1499 diff --git a/bar2 b/bar2
1500 1500 1 hunks, 1 lines changed
1501 1501 examine changes to 'bar2'?
1502 1502 (enter ? for help) [Ynesfdaq?] y
1503 1503
1504 1504 @@ -1,2 +1,3 @@
1505 1505 A
1506 1506 +B
1507 1507 C
1508 1508 record this change to 'bar2'?
1509 1509 (enter ? for help) [Ynesfdaq?] y
1510 1510
1511 1511 -- test for --interactive --keep
1512 1512 $ hg unshelve -i --keep
1513 1513 abort: --keep on --interactive is not yet supported
1514 1514 [10]
1515 1515
1516 1516 $ hg update -q --clean .
1517 1517
1518 1518 Test that we can successfully shelve and unshelve a file with a trailing space
1519 1519 in the filename. Such filenames are supposedly unsupported on Windows, so we
1520 1520 wrap it in the no-windows check. Also test `hg patch` of the .patch file
1521 1521 produced by `hg shelve`.
1522 1522 #if no-windows
1523 1523 $ echo hi > 'my filename '
1524 1524 $ hg add 'my filename '
1525 1525 warning: filename ends with ' ', which is not allowed on Windows: 'my filename '
1526 1526 $ hg shelve
1527 1527 shelved as default-01
1528 1528 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1529 1529 $ cp .hg/shelved/default-01.patch test_patch.patch
1530 1530 $ hg unshelve
1531 1531 unshelving change 'default-01'
1532 1532 $ cat 'my filename '
1533 1533 hi
1534 1534 $ hg update -q --clean .
1535 1535 $ hg patch -p1 test_patch.patch
1536 1536 applying test_patch.patch
1537 1537 #endif
General Comments 0
You need to be logged in to leave comments. Login now