comparison mercurial/shelve.py @ 46272:a68d3386138c

shelve: raise more specific errors Differential Revision: https://phab.mercurial-scm.org/D9699
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 07 Jan 2021 12:26:32 -0800
parents b2a8ff736ecf
children efc71bb71682
comparison
equal deleted inserted replaced
46271:b2a8ff736ecf 46272:a68d3386138c
590 590
591 591
592 def deletecmd(ui, repo, pats): 592 def deletecmd(ui, repo, pats):
593 """subcommand that deletes a specific shelve""" 593 """subcommand that deletes a specific shelve"""
594 if not pats: 594 if not pats:
595 raise error.Abort(_(b'no shelved changes specified!')) 595 raise error.InputError(_(b'no shelved changes specified!'))
596 with repo.wlock(): 596 with repo.wlock():
597 for name in pats: 597 for name in pats:
598 if not shelvedfile(repo, name, patchextension).exists(): 598 if not shelvedfile(repo, name, patchextension).exists():
599 raise error.Abort(_(b"shelved change '%s' not found") % name) 599 raise error.InputError(
600 _(b"shelved change '%s' not found") % name
601 )
600 for suffix in shelvefileextensions: 602 for suffix in shelvefileextensions:
601 shfile = shelvedfile(repo, name, suffix) 603 shfile = shelvedfile(repo, name, suffix)
602 if shfile.exists(): 604 if shfile.exists():
603 shfile.movetobackup() 605 shfile.movetobackup()
604 cleanupoldbackups(repo) 606 cleanupoldbackups(repo)
1064 shelved = list(shelved) 1066 shelved = list(shelved)
1065 if opts.get(b"name"): 1067 if opts.get(b"name"):
1066 shelved.append(opts[b"name"]) 1068 shelved.append(opts[b"name"])
1067 1069
1068 if interactive and opts.get(b'keep'): 1070 if interactive and opts.get(b'keep'):
1069 raise error.Abort(_(b'--keep on --interactive is not yet supported')) 1071 raise error.InputError(
1072 _(b'--keep on --interactive is not yet supported')
1073 )
1070 if abortf or continuef: 1074 if abortf or continuef:
1071 if abortf and continuef: 1075 if abortf and continuef:
1072 raise error.Abort(_(b'cannot use both abort and continue')) 1076 raise error.InputError(_(b'cannot use both abort and continue'))
1073 if shelved: 1077 if shelved:
1074 raise error.Abort( 1078 raise error.InputError(
1075 _( 1079 _(
1076 b'cannot combine abort/continue with ' 1080 b'cannot combine abort/continue with '
1077 b'naming a shelved change' 1081 b'naming a shelved change'
1078 ) 1082 )
1079 ) 1083 )
1082 1086
1083 state = _loadshelvedstate(ui, repo, opts) 1087 state = _loadshelvedstate(ui, repo, opts)
1084 if abortf: 1088 if abortf:
1085 return unshelveabort(ui, repo, state) 1089 return unshelveabort(ui, repo, state)
1086 elif continuef and interactive: 1090 elif continuef and interactive:
1087 raise error.Abort(_(b'cannot use both continue and interactive')) 1091 raise error.InputError(
1092 _(b'cannot use both continue and interactive')
1093 )
1088 elif continuef: 1094 elif continuef:
1089 return unshelvecontinue(ui, repo, state, opts) 1095 return unshelvecontinue(ui, repo, state, opts)
1090 elif len(shelved) > 1: 1096 elif len(shelved) > 1:
1091 raise error.Abort(_(b'can only unshelve one change at a time')) 1097 raise error.InputError(_(b'can only unshelve one change at a time'))
1092 elif not shelved: 1098 elif not shelved:
1093 shelved = listshelves(repo) 1099 shelved = listshelves(repo)
1094 if not shelved: 1100 if not shelved:
1095 raise error.Abort(_(b'no shelved changes to apply!')) 1101 raise error.StateError(_(b'no shelved changes to apply!'))
1096 basename = util.split(shelved[0][1])[1] 1102 basename = util.split(shelved[0][1])[1]
1097 ui.status(_(b"unshelving change '%s'\n") % basename) 1103 ui.status(_(b"unshelving change '%s'\n") % basename)
1098 else: 1104 else:
1099 basename = shelved[0] 1105 basename = shelved[0]
1100 1106
1101 if not shelvedfile(repo, basename, patchextension).exists(): 1107 if not shelvedfile(repo, basename, patchextension).exists():
1102 raise error.Abort(_(b"shelved change '%s' not found") % basename) 1108 raise error.InputError(_(b"shelved change '%s' not found") % basename)
1103 1109
1104 return _dounshelve(ui, repo, basename, opts) 1110 return _dounshelve(ui, repo, basename, opts)
1105 1111
1106 1112
1107 def _dounshelve(ui, repo, basename, opts): 1113 def _dounshelve(ui, repo, basename, opts):