diff --git a/hggit/__init__.py b/hggit/__init__.py
index 7f2b1bd5529eb0b06dc5198776a09f01b03f1cfb_aGdnaXQvX19pbml0X18ucHk=..1bddbd70be215f64fdf4778c3208c0bd64b00d5b_aGdnaXQvX19pbml0X18ucHk= 100644
--- a/hggit/__init__.py
+++ b/hggit/__init__.py
@@ -31,7 +31,7 @@
 from bisect import insort
 from .git_handler import GitHandler
 from mercurial.node import bin, hex
-from mercurial.error import LookupError
+from mercurial.error import AmbiguousPrefixLookupError
 from mercurial.i18n import _
 from mercurial import (
     bundlerepo,
@@ -476,7 +476,7 @@
     result = revset.baseset(r for r in subset if matches(r))
     if 0 <= len(result) < 2:
         return result
-    raise LookupError(rev, git.map_file, _(b'ambiguous identifier'))
+    raise AmbiguousPrefixLookupError(rev, git.map_file, _(b'ambiguous identifier'))
 
 
 def _gitnodekw(node, repo):
diff --git a/tests/test-ambiguousprefix.t b/tests/test-ambiguousprefix.t
new file mode 100644
index 0000000000000000000000000000000000000000..1bddbd70be215f64fdf4778c3208c0bd64b00d5b_dGVzdHMvdGVzdC1hbWJpZ3VvdXNwcmVmaXgudA==
--- /dev/null
+++ b/tests/test-ambiguousprefix.t
@@ -0,0 +1,31 @@
+Load commonly used test logic
+  $ . "$TESTDIR/testutil"
+
+  $ git init gitrepo
+  Initialized empty Git repository in $TESTTMP/gitrepo/.git/
+  $ cd gitrepo
+  $ echo alpha > alpha
+  $ git add alpha
+  $ fn_git_commit -m 'add alpha'
+  $ echo beta > beta
+  $ git add beta
+  $ fn_git_commit -m 'add beta'
+
+This commit is called gamma10 so that its hash will have the same initial digit
+as commit alpha. This lets us test ambiguous abbreviated identifiers.
+
+  $ echo gamma10 > gamma10
+  $ git add gamma10
+  $ fn_git_commit -m 'add gamma10'
+
+  $ cd ..
+
+  $ hg clone gitrepo hgrepo | grep -v '^updating'
+  importing git objects into hg
+  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ cd hgrepo
+
+  $ hg log -r 'gitnode(7e)'
+  abort: git-mapfile@7e: ambiguous identifier!
+  [255]