Patchwork D8271: git: correctly handle p1() on dirstate when underlying git repo is empty

login
register
mail settings
Submitter phabricator
Date March 10, 2020, 5:15 p.m.
Message ID <differential-rev-PHID-DREV-zjga2frrdctz5eidkx3m-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45667/
State Superseded
Headers show

Comments

phabricator - March 10, 2020, 5:15 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This shows up in my next change, which ends up making an empty git
  repo and then running hg.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8271

AFFECTED FILES
  hgext/git/dirstate.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/hgext/git/dirstate.py b/hgext/git/dirstate.py
--- a/hgext/git/dirstate.py
+++ b/hgext/git/dirstate.py
@@ -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?