changeset 44492:eb061d272af4

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
author Augie Fackler <raf@durin42.com>
date Tue, 10 Mar 2020 13:10:45 -0400
parents fb16ad368606
children 02c47b74366c
files hgext/git/dirstate.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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?