git: correctly handle p1() on dirstate when underlying git repo is empty
This shows up in my next change, which ends up making an empty git
repo and then running hg.
Differential Revision: https://phab.mercurial-scm.org/D8271
--- a/hgext/git/dirstate.py Tue Mar 10 14:24:08 2020 +0100
+++ b/hgext/git/dirstate.py Tue Mar 10 13:10:45 2020 -0400
@@ -76,7 +76,12 @@
self._plchangecallbacks = {}
def p1(self):
- return self.git.head.peel().id.raw
+ try:
+ return self.git.head.peel().id.raw
+ except pygit2.GitError:
+ # Typically happens when peeling HEAD fails, as in an
+ # empty repository.
+ return nodemod.nullid
def p2(self):
# TODO: MERGE_HEAD? something like that, right?