[bitbake-devel] [PATCH 1/2] tests/fetch: add test_git_submodule_branch_new_module

Christopher Larson kergoth at gmail.com
Mon Aug 21 16:37:40 UTC 2017


From: Christopher Larson <chris_larson at mentor.com>

This local test validates that we can switch branches for a gitsm URI and the
submodules are correct for that branch when unpacked.

[YOCTO #11830]

Signed-off-by: Christopher Larson <chris_larson at mentor.com>
---
 lib/bb/tests/fetch.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 57 insertions(+), 3 deletions(-)

diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index faa5c74a..f91621c0 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -19,11 +19,12 @@
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 #
 
-import unittest
-import tempfile
-import subprocess
 import collections
 import os
+import shutil
+import subprocess
+import tempfile
+import unittest
 from bb.fetch2 import URI
 from bb.fetch2 import FetchMethod
 import bb
@@ -517,6 +518,59 @@ class FetcherLocalTest(FetcherTest):
         with self.assertRaises(bb.fetch2.UnpackError):
             self.fetchUnpack(['file://a;subdir=/bin/sh'])
 
+    def test_git_submodule_branch_new_module(self):
+        def git(gitdir, *cmd):
+            if len(cmd) == 1 and isinstance(cmd[0], list, str):
+                cmd = cmd[0]
+
+            if isinstance(cmd, str):
+                cmd = 'git ' + cmd
+            else:
+                cmd = ['git'] + list(cmd)
+            return bb.process.run(cmd, cwd=gitdir)[0]
+
+        def newrepo(name):
+            gitdir = os.path.join(self.tempdir, name)
+            bb.process.run(['git', 'init', gitdir])
+            open(os.path.join(gitdir, 'a'), 'w').close()
+            git(gitdir, 'add', 'a')
+            git(gitdir, 'commit', '-m', 'add a')
+            return gitdir
+
+        sub1 = newrepo('upstream-submodule1')
+        upstream = newrepo('upstream')
+        git(upstream, 'submodule', 'add', sub1, 'sub1')
+        git(upstream, 'add', '.gitmodules')
+        git(upstream, 'commit', '-m', 'add submodule1')
+
+        git(upstream, 'checkout', '-b', 'with-sub2')
+        sub2 = newrepo('upstream-submodule2')
+        git(upstream, 'submodule', 'add', sub2, 'sub2')
+        git(upstream, 'add', '.gitmodules')
+        git(upstream, 'commit', '-m', 'add submodule2')
+
+        git(upstream, 'checkout', 'master')
+
+        self.d.setVar('SRCREV', '${@bb.fetch2.get_autorev(d)}')
+
+        bb.utils.mkdirhier(self.unpackdir)
+        tree = self.fetchUnpack(["gitsm://%s;protocol=file;branch=master" % upstream])
+        tree = filter(lambda f: not f.startswith('git/.git/'), tree)
+        self.assertEqual(list(tree), ['git/.gitmodules', 'git/a', 'git/sub1/.git', 'git/sub1/a'])
+
+        shutil.rmtree(self.unpackdir)
+        bb.utils.mkdirhier(self.unpackdir)
+        tree = self.fetchUnpack(["gitsm://%s;protocol=file;branch=with-sub2" % upstream])
+        tree = filter(lambda f: not f.startswith('git/.git/'), tree)
+        self.assertEqual(list(tree), ['git/.gitmodules', 'git/a', 'git/sub1/.git', 'git/sub1/a', 'git/sub2/.git', 'git/sub2/a'])
+
+        shutil.rmtree(self.unpackdir)
+        bb.utils.mkdirhier(self.unpackdir)
+        tree = self.fetchUnpack(["gitsm://%s;protocol=file;branch=master" % upstream])
+        tree = filter(lambda f: not f.startswith('git/.git/'), tree)
+        self.assertEqual(list(tree), ['git/.gitmodules', 'git/a', 'git/sub1/.git', 'git/sub1/a'])
+
+
 class FetcherNetworkTest(FetcherTest):
 
     if os.environ.get("BB_SKIP_NETTESTS") == "yes":
-- 
2.11.1




More information about the bitbake-devel mailing list