diff --git a/hgext/git/__init__.py b/hgext/git/__init__.py --- a/hgext/git/__init__.py +++ b/hgext/git/__init__.py @@ -8,8 +8,6 @@ import os -import pygit2 - from mercurial.i18n import _ from mercurial import ( @@ -22,12 +20,21 @@ util, ) -from . import ( - dirstate, - gitlog, - gitutil, - index, -) +# gendoc.py ends up causing all extensions to be imported, so we need +# to hide attempts to load pygit2 from it so that it can finish +# generating documentation. +try: + import pygit2 +except ImportError: + pygit2 = None + +if pygit2 is not None: + from . import ( + dirstate, + gitlog, + gitutil, + index, + ) # TODO: extract an interface for this in core @@ -250,6 +257,7 @@ def extsetup(ui): + assert pygit2 is not None, 'git extension requires pygit2' extensions.wrapfunction(localrepo, b'makestore', _makestore) extensions.wrapfunction(localrepo, b'makefilestorage', _makefilestorage) # Inject --git flag for `hg init`