diff hgext/convert/git.py @ 25699:5c97a4ecbdd4

convert: improve support for unusual .gitmodules Previously convert would throw an exception if it encountered a git commit with a .gitmodules file that was malformed (i.e. was missing, but had submodule files, or was malformed). Instead of breaking the convert entirely, let's print error messages and move on.
author Durham Goode <durham@fb.com>
date Mon, 29 Jun 2015 17:19:58 -0700
parents 307370c2dda2
children baea47cafe75
line wrap: on
line diff
--- a/hgext/convert/git.py	Mon Jun 29 17:19:18 2015 -0700
+++ b/hgext/convert/git.py	Mon Jun 29 17:19:58 2015 -0700
@@ -7,7 +7,7 @@
 
 import os
 import subprocess
-from mercurial import util, config
+from mercurial import util, config, error
 from mercurial.node import hex, nullid
 from mercurial.i18n import _
 
@@ -185,9 +185,19 @@
     def retrievegitmodules(self, version):
         modules, ret = self.gitread("git show %s:%s" % (version, '.gitmodules'))
         if ret:
-            raise util.Abort(_('cannot read submodules config file in %s') %
-                             version)
-        self.parsegitmodules(modules)
+            # This can happen if a file is in the repo that has permissions
+            # 160000, but there is no .gitmodules file.
+            self.ui.warn(_("warning: cannot read submodules config file in "
+                           "%s\n") % version)
+            return
+
+        try:
+            self.parsegitmodules(modules)
+        except error.ParseError:
+            self.ui.warn(_("warning: unable to parse .gitmodules in %s\n")
+                         % version)
+            return
+
         for m in self.submodules:
             node, ret = self.gitread("git rev-parse %s:%s" % (version, m.path))
             if ret: