diff --git a/mercurial/shelve.py b/mercurial/shelve.py --- a/mercurial/shelve.py +++ b/mercurial/shelve.py @@ -600,20 +600,12 @@ def deletecmd(ui, repo, pats): raise error.Abort(_(b'no shelved changes specified!')) with repo.wlock(): for name in pats: - try: - for suffix in shelvefileextensions: - shfile = shelvedfile(repo, name, suffix) - # patch file is necessary, as it should - # be present for any kind of shelve, - # but the .hg file is optional as in future we - # will add obsolete shelve with does not create a - # bundle - if shfile.exists() or suffix == patchextension: - shfile.movetobackup() - except OSError as err: - if err.errno != errno.ENOENT: - raise + if not shelvedfile(repo, name, patchextension).exists(): raise error.Abort(_(b"shelved change '%s' not found") % name) + for suffix in shelvefileextensions: + shfile = shelvedfile(repo, name, suffix) + if shfile.exists(): + shfile.movetobackup() cleanupoldbackups(repo) diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t --- a/tests/test-shelve2.t +++ b/tests/test-shelve2.t @@ -776,8 +776,8 @@ Test corrupt shelves (in .hg/shelved/, n $ find .hg/shelve* | sort .hg/shelve-backup .hg/shelve-backup/junk1.patch - .hg/shelve-backup/junk2.hg .hg/shelved + .hg/shelved/junk2.hg # A file with an unexpected extension $ touch .hg/shelved/junk3 @@ -791,8 +791,8 @@ Test corrupt shelves (in .hg/shelved/, n $ find .hg/shelve* | sort .hg/shelve-backup .hg/shelve-backup/junk1.patch - .hg/shelve-backup/junk2.hg .hg/shelved + .hg/shelved/junk2.hg .hg/shelved/junk3 $ cd ..