##// END OF EJS Templates
abort: added support for unshelve...
Taapas Agrawal -
r42802:3fb04938 default
parent child Browse files
Show More
@@ -6182,6 +6182,12 b' def unshelve(ui, repo, *shelved, **opts)'
6182 with repo.wlock():
6182 with repo.wlock():
6183 return shelvemod.dounshelve(ui, repo, *shelved, **opts)
6183 return shelvemod.dounshelve(ui, repo, *shelved, **opts)
6184
6184
6185 statemod.addunfinished(
6186 'unshelve', fname='shelvedstate', continueflag=True,
6187 abortfunc=shelvemod.hgabortunshelve,
6188 cmdmsg=_('unshelve already in progress'),
6189 )
6190
6185 @command('update|up|checkout|co',
6191 @command('update|up|checkout|co',
6186 [('C', 'clean', None, _('discard uncommitted changes (no backup)')),
6192 [('C', 'clean', None, _('discard uncommitted changes (no backup)')),
6187 ('c', 'check', None, _('require clean working directory')),
6193 ('c', 'check', None, _('require clean working directory')),
@@ -624,7 +624,30 b' def checkparents(repo, state):'
624 raise error.Abort(_('working directory parents do not match unshelve '
624 raise error.Abort(_('working directory parents do not match unshelve '
625 'state'))
625 'state'))
626
626
627 def unshelveabort(ui, repo, state, opts):
627 def _loadshelvedstate(ui, repo, opts):
628 try:
629 state = shelvedstate.load(repo)
630 if opts.get('keep') is None:
631 opts['keep'] = state.keep
632 except IOError as err:
633 if err.errno != errno.ENOENT:
634 raise
635 cmdutil.wrongtooltocontinue(repo, _('unshelve'))
636 except error.CorruptedState as err:
637 ui.debug(pycompat.bytestr(err) + '\n')
638 if opts.get('continue'):
639 msg = _('corrupted shelved state file')
640 hint = _('please run hg unshelve --abort to abort unshelve '
641 'operation')
642 raise error.Abort(msg, hint=hint)
643 elif opts.get('abort'):
644 shelvedstate.clear(repo)
645 raise error.Abort(_('could not read shelved state file, your '
646 'working copy may be in an unexpected state\n'
647 'please update to some commit\n'))
648 return state
649
650 def unshelveabort(ui, repo, state):
628 """subcommand that abort an in-progress unshelve"""
651 """subcommand that abort an in-progress unshelve"""
629 with repo.lock():
652 with repo.lock():
630 try:
653 try:
@@ -642,6 +665,12 b' def unshelveabort(ui, repo, state, opts)'
642 shelvedstate.clear(repo)
665 shelvedstate.clear(repo)
643 ui.warn(_("unshelve of '%s' aborted\n") % state.name)
666 ui.warn(_("unshelve of '%s' aborted\n") % state.name)
644
667
668 def hgabortunshelve(ui, repo):
669 """logic to abort unshelve using 'hg abort"""
670 with repo.wlock():
671 state = _loadshelvedstate(ui, repo, {'abort' : True})
672 return unshelveabort(ui, repo, state)
673
645 def mergefiles(ui, repo, wctx, shelvectx):
674 def mergefiles(ui, repo, wctx, shelvectx):
646 """updates to wctx and merges the changes from shelvectx into the
675 """updates to wctx and merges the changes from shelvectx into the
647 dirstate."""
676 dirstate."""
@@ -665,7 +694,6 b' def unshelvecleanup(ui, repo, name, opts'
665 if shfile.exists():
694 if shfile.exists():
666 shfile.movetobackup()
695 shfile.movetobackup()
667 cleanupoldbackups(repo)
696 cleanupoldbackups(repo)
668
669 def unshelvecontinue(ui, repo, state, opts):
697 def unshelvecontinue(ui, repo, state, opts):
670 """subcommand to continue an in-progress unshelve"""
698 """subcommand to continue an in-progress unshelve"""
671 # We're finishing off a merge. First parent is our original
699 # We're finishing off a merge. First parent is our original
@@ -864,29 +892,9 b' def dounshelve(ui, repo, *shelved, **opt'
864 if abortf and opts.get('tool', False):
892 if abortf and opts.get('tool', False):
865 ui.warn(_('tool option will be ignored\n'))
893 ui.warn(_('tool option will be ignored\n'))
866
894
867 try:
895 state = _loadshelvedstate(ui, repo, opts)
868 state = shelvedstate.load(repo)
869 if opts.get('keep') is None:
870 opts['keep'] = state.keep
871 except IOError as err:
872 if err.errno != errno.ENOENT:
873 raise
874 cmdutil.wrongtooltocontinue(repo, _('unshelve'))
875 except error.CorruptedState as err:
876 ui.debug(pycompat.bytestr(err) + '\n')
877 if continuef:
878 msg = _('corrupted shelved state file')
879 hint = _('please run hg unshelve --abort to abort unshelve '
880 'operation')
881 raise error.Abort(msg, hint=hint)
882 elif abortf:
883 shelvedstate.clear(repo)
884 raise error.Abort(_('could not read shelved state file, your '
885 'working copy may be in an unexpected state\n'
886 'please update to some commit\n'))
887
888 if abortf:
896 if abortf:
889 return unshelveabort(ui, repo, state, opts)
897 return unshelveabort(ui, repo, state)
890 elif continuef:
898 elif continuef:
891 return unshelvecontinue(ui, repo, state, opts)
899 return unshelvecontinue(ui, repo, state, opts)
892 elif len(shelved) > 1:
900 elif len(shelved) > 1:
@@ -194,10 +194,6 b' def addunfinished(opname, fname, clearab'
194 _unfinishedstates.insert(0, statecheckobj)
194 _unfinishedstates.insert(0, statecheckobj)
195
195
196 addunfinished(
196 addunfinished(
197 'unshelve', fname='shelvedstate', continueflag=True,
198 cmdmsg=_('unshelve already in progress')
199 )
200 addunfinished(
201 'update', fname='updatestate', clearable=True,
197 'update', fname='updatestate', clearable=True,
202 cmdmsg=_('last update was interrupted'),
198 cmdmsg=_('last update was interrupted'),
203 cmdhint=_("use 'hg update' to get a consistent checkout"),
199 cmdhint=_("use 'hg update' to get a consistent checkout"),
@@ -1,4 +1,5 b''
1 #testcases stripbased phasebased
1 #testcases stripbased phasebased
2 #testcases abortflag abortcommand
2
3
3 $ cat <<EOF >> $HGRCPATH
4 $ cat <<EOF >> $HGRCPATH
4 > [extensions]
5 > [extensions]
@@ -19,6 +20,13 b''
19
20
20 #endif
21 #endif
21
22
23 #if abortflag
24 $ cat >> $HGRCPATH <<EOF
25 > [alias]
26 > abort = unshelve --abort
27 > EOF
28 #endif
29
22 shelve should leave dirstate clean (issue4055)
30 shelve should leave dirstate clean (issue4055)
23
31
24 $ hg init shelverebase
32 $ hg init shelverebase
@@ -285,7 +293,14 b' unshelve and conflicts with tracked and '
285 >>>>>>> working-copy: aef214a5229c - shelve: changes to: commit stuff
293 >>>>>>> working-copy: aef214a5229c - shelve: changes to: commit stuff
286 $ cat f.orig
294 $ cat f.orig
287 g
295 g
288 $ hg unshelve --abort
296
297 #if abortcommand
298 when in dry-run mode
299 $ hg abort --dry-run
300 unshelve in progress, will be aborted
301 #endif
302
303 $ hg abort
289 unshelve of 'default' aborted
304 unshelve of 'default' aborted
290 $ hg st
305 $ hg st
291 ? f.orig
306 ? f.orig
@@ -695,7 +710,7 b' Unshelve --continue fails with appropria'
695 [255]
710 [255]
696
711
697 Unshelve --abort works with a corrupted shelvedstate
712 Unshelve --abort works with a corrupted shelvedstate
698 $ hg unshelve --abort
713 $ hg abort
699 abort: could not read shelved state file, your working copy may be in an unexpected state
714 abort: could not read shelved state file, your working copy may be in an unexpected state
700 please update to some commit
715 please update to some commit
701
716
@@ -703,8 +718,10 b' Unshelve --abort works with a corrupted '
703
718
704 Unshelve --abort fails with appropriate message if there's no unshelve in
719 Unshelve --abort fails with appropriate message if there's no unshelve in
705 progress
720 progress
706 $ hg unshelve --abort
721 $ hg abort
707 abort: no unshelve in progress
722 abort: no unshelve in progress (abortflag !)
723 abort: merge in progress but does not support 'hg abort' (no-abortflag !)
724 (use 'hg commit' or 'hg merge --abort') (no-abortflag !)
708 [255]
725 [255]
709 $ cd ..
726 $ cd ..
710
727
@@ -824,7 +841,7 b' Test with the `.shelve` missing, but the'
824 warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
841 warning: conflicts while merging a! (edit, then use 'hg resolve --mark')
825 unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
842 unresolved conflicts (see 'hg resolve', then 'hg unshelve --continue')
826 [1]
843 [1]
827 $ hg unshelve --abort
844 $ hg abort
828 unshelve of 'default' aborted
845 unshelve of 'default' aborted
829
846
830 Unshelve without .shelve metadata (can happen when upgrading a repository with old shelve)
847 Unshelve without .shelve metadata (can happen when upgrading a repository with old shelve)
@@ -843,7 +860,7 b' Unshelve without .shelve metadata (can h'
843 [1]
860 [1]
844 $ cat .hg/shelved/default.shelve
861 $ cat .hg/shelved/default.shelve
845 node=82e0cb9893247d12667017593ce1e5655860f1ac
862 node=82e0cb9893247d12667017593ce1e5655860f1ac
846 $ hg unshelve --abort
863 $ hg abort
847 unshelve of 'default' aborted
864 unshelve of 'default' aborted
848
865
849 #endif
866 #endif
General Comments 0
You need to be logged in to leave comments. Login now