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:26 p.m.
Message ID <b80735ca66924631bd54d76c98bf856d@localhost.localdomain>
Download mbox | patch
Permalink /patch/45669/
State Not Applicable
Headers show

Comments

phabricator - March 10, 2020, 5:26 p.m.
Closed by commit rHGeb061d272af4: git: correctly handle p1() on dirstate when underlying git repo is empty (authored by durin42).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8271?vs=20668&id=20670

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8271/new/

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?