##// END OF EJS Templates
shelve: make unshelve be able to abort in any case
Kostia Balytskyi -
r29536:b17a6e3c default
parent child Browse files
Show More
@@ -165,21 +165,26 class shelvedstate(object):
165 165 raise error.Abort(_('this version of shelve is incompatible '
166 166 'with the version used in this repo'))
167 167 name = fp.readline().strip()
168 wctx = fp.readline().strip()
169 pendingctx = fp.readline().strip()
168 wctx = nodemod.bin(fp.readline().strip())
169 pendingctx = nodemod.bin(fp.readline().strip())
170 170 parents = [nodemod.bin(h) for h in fp.readline().split()]
171 171 stripnodes = [nodemod.bin(h) for h in fp.readline().split()]
172 172 branchtorestore = fp.readline().strip()
173 except (ValueError, TypeError) as err:
174 raise error.CorruptedState(str(err))
173 175 finally:
174 176 fp.close()
175 177
178 try:
176 179 obj = cls()
177 180 obj.name = name
178 obj.wctx = repo[nodemod.bin(wctx)]
179 obj.pendingctx = repo[nodemod.bin(pendingctx)]
181 obj.wctx = repo[wctx]
182 obj.pendingctx = repo[pendingctx]
180 183 obj.parents = parents
181 184 obj.stripnodes = stripnodes
182 185 obj.branchtorestore = branchtorestore
186 except error.RepoLookupError as err:
187 raise error.CorruptedState(str(err))
183 188
184 189 return obj
185 190
@@ -666,6 +671,20 def _dounshelve(ui, repo, *shelved, **op
666 671 if err.errno != errno.ENOENT:
667 672 raise
668 673 cmdutil.wrongtooltocontinue(repo, _('unshelve'))
674 except error.CorruptedState as err:
675 ui.debug(str(err) + '\n')
676 if continuef:
677 msg = _('corrupted shelved state file')
678 hint = _('please run hg unshelve --abort to abort unshelve '
679 'operation')
680 raise error.Abort(msg, hint=hint)
681 elif abortf:
682 msg = _('could not read shelved state file, your working copy '
683 'may be in an unexpected state\nplease update to some '
684 'commit\n')
685 ui.warn(msg)
686 shelvedstate.clear(repo)
687 return
669 688
670 689 if abortf:
671 690 return unshelveabort(ui, repo, state, opts)
@@ -240,3 +240,6 class InvalidBundleSpecification(Excepti
240 240
241 241 class UnsupportedBundleSpecification(Exception):
242 242 """error raised when a bundle specification is not supported."""
243
244 class CorruptedState(Exception):
245 """error raised when a command is not able to read its state from file"""
@@ -1585,3 +1585,40 On non bare shelve the branch informatio
1585 1585 ? b
1586 1586 $ hg branch
1587 1587 default
1588 $ cd ..
1589
1590 Prepare unshleve with a corrupted shelvedstate
1591 $ hg init r1 && cd r1
1592 $ echo text1 > file && hg add file
1593 $ hg shelve
1594 shelved as default
1595 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1596 $ echo text2 > file && hg ci -Am text1
1597 adding file
1598 $ hg unshelve
1599 unshelving change 'default'
1600 rebasing shelved changes
1601 rebasing 1:396ea74229f9 "(changes in empty repository)" (tip)
1602 merging file
1603 warning: conflicts while merging file! (edit, then use 'hg resolve --mark')
1604 unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
1605 [1]
1606 $ echo somethingsomething > .hg/shelvedstate
1607
1608 Unshelve --continue fails with appropriate message if shelvedstate is corrupted
1609 $ hg unshelve --continue
1610 abort: corrupted shelved state file
1611 (please run hg unshelve --abort to abort unshelve operation)
1612 [255]
1613
1614 Unshelve --abort works with a corrupted shelvedstate
1615 $ hg unshelve --abort
1616 could not read shelved state file, your working copy may be in an unexpected state
1617 please update to some commit
1618
1619 Unshelve --abort fails with appropriate message if there's no unshelve in
1620 progress
1621 $ hg unshelve --abort
1622 abort: no unshelve in progress
1623 [255]
1624 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now