git: correctly handle p1() on dirstate when underlying git repo is empty
authorAugie Fackler <raf@durin42.com>
Tue, 10 Mar 2020 13:10:45 -0400
changeset 44492 eb061d272af4
parent 44491 fb16ad368606
child 44493 02c47b74366c
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
hgext/git/dirstate.py
--- 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?