# HG changeset patch # User Martin von Zweigbergk # Date 2021-01-09 07:08:37 # Node ID c062874a35dbc1a68e2f28f14857f509f8f7b197 # Parent 61f8fc12e16735d7a6d55ed0dcadabdc1dc073a1 shelve: don't crash on file with unexpected extension in .hg/shelved/ We assumed that the files in the `.hg/shelved/` directory have an extension. That's a valid assumption except that users may put garbage in the directory. This patch fixes the crash by simply not assuming that the result of splittin a string at '.' yields an extension. We don't use the extension since the previous patch anyway. Differential Revision: https://phab.mercurial-scm.org/D9720 diff --git a/mercurial/shelve.py b/mercurial/shelve.py --- a/mercurial/shelve.py +++ b/mercurial/shelve.py @@ -625,7 +625,7 @@ def listshelves(repo): info = [] seen = set() for (filename, _type) in names: - name, ext = filename.rsplit(b'.', 1) + name = filename.rsplit(b'.', 1)[0] if name in seen: continue seen.add(name) diff --git a/tests/test-shelve2.t b/tests/test-shelve2.t --- a/tests/test-shelve2.t +++ b/tests/test-shelve2.t @@ -779,10 +779,10 @@ Test corrupt shelves (in .hg/shelved/, n # A file with an unexpected extension $ touch .hg/shelved/junk3 - $ hg shelve -l 2>&1 | grep ValueError - ValueError: * (glob) - $ hg unshelve 2>&1 | grep ValueError - ValueError: * (glob) + $ hg shelve -l + $ hg unshelve + abort: no shelved changes to apply! + [20] $ hg shelve -d junk3 abort: shelved change 'junk3' not found [10]