[PATCH 3 of 5] convert: handle .gitmodules with non-tab whitespaces

Durham Goode durham at fb.com
Mon Jun 29 20:44:03 CDT 2015


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1435623558 25200
#      Mon Jun 29 17:19:18 2015 -0700
# Node ID 3e439040f3a1fe09af1291691f1f788e0e28c48a
# Parent  2fb1cd9032338750bfe16e0c21933bbb622c9da0
convert: handle .gitmodules with non-tab whitespaces

The old implementation assumed .gitmodules file lines always began with tags. It
can be any whitespace, so lets trim the lines appropriately.

diff --git a/hgext/convert/git.py b/hgext/convert/git.py
--- a/hgext/convert/git.py
+++ b/hgext/convert/git.py
@@ -174,8 +174,9 @@ class convert_git(converter_source):
         """
         self.submodules = []
         c = config.config()
-        # Each item in .gitmodules starts with \t that cant be parsed
-        c.parse('.gitmodules', content.replace('\t',''))
+        # Each item in .gitmodules starts with whitespace that cant be parsed
+        c.parse('.gitmodules', '\n'.join(line.strip() for line in
+                               content.split('\n')))
         for sec in c.sections():
             s = c[sec]
             if 'url' in s and 'path' in s:
diff --git a/tests/test-convert-git.t b/tests/test-convert-git.t
--- a/tests/test-convert-git.t
+++ b/tests/test-convert-git.t
@@ -457,6 +457,31 @@ test sub modules
   $ git init-db >/dev/null 2>/dev/null
   $ git submodule add ${BASE} >/dev/null 2>/dev/null
   $ commit -a -m 'addsubmodule' >/dev/null 2>/dev/null
+
+test non-tab whitespace .gitmodules
+
+  $ cat >> .gitmodules <<EOF
+  > [submodule "git-repo5"]
+  >   path = git-repo5
+  >   url = $TESTTMP/git-repo5
+  > EOF
+  $ git commit -a -m "weird white space submodule"
+  [master *] weird white space submodule (glob)
+   Author: nottest <test at example.org>
+   1 file changed, 3 insertions(+)
+  $ cd ..
+  $ hg convert git-repo6 hg-repo6
+  initializing destination hg-repo6 repository
+  scanning source...
+  sorting...
+  converting...
+  1 addsubmodule
+  0 weird white space submodule
+  updating bookmarks
+
+  $ rm -rf hg-repo6
+  $ cd git-repo6
+  $ git reset --hard 'HEAD^' > /dev/null
   $ cd ..
 
 test invalid splicemap1


More information about the Mercurial-devel mailing list