diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py +++ b/mercurial/templatefuncs.py @@ -12,6 +12,7 @@ import re from .i18n import _ from .node import ( bin, + wdirid, ) from . import ( color, @@ -601,7 +602,9 @@ def shortest(context, mapping, args): else: try: node = scmutil.resolvehexnodeidprefix(repo, hexnode) - except (error.LookupError, error.WdirUnsupported): + except error.WdirUnsupported: + node = wdirid + except error.LookupError: return hexnode if not node: return hexnode diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -3916,6 +3916,15 @@ Test shortest(node) function: $ hg log --template '{shortest("not a hex string, but it'\''s 40 bytes long")}\n' -l1 not a hex string, but it's 40 bytes long + $ hg log --template '{shortest("ffffffffffffffffffffffffffffffffffffffff")}\n' -l1 + ffff + + $ hg log --template '{shortest("fffffff")}\n' -l1 + ffff + + $ hg log --template '{shortest("ff")}\n' -l1 + ffff + $ cd .. Test shortest(node) with the repo having short hash collision: