diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py +++ b/mercurial/templatefuncs.py @@ -12,6 +12,7 @@ from .i18n import _ from .node import ( bin, + wdirid, ) from . import ( color, @@ -601,7 +602,9 @@ 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 @@ -3901,8 +3901,8 @@ $ hg log -r 'wdir()' -T '{node|shortest}\n' ffff - $ hg log --template '{shortest("f")}\n' -l1 - f + $ hg log --template '{shortest("a")}\n' -l1 + a $ hg log --template '{shortest("0123456789012345678901234567890123456789")}\n' -l1 0123456789012345678901234567890123456789 @@ -3916,6 +3916,15 @@ $ 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("f")}\n' -l1 + ffff + $ cd .. Test shortest(node) with the repo having short hash collision: