All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christopher Larson <kergoth@gmail.com>
To: bitbake-devel@lists.openembedded.org
Cc: Christopher Larson <chris_larson@mentor.com>
Subject: [PATCH 1/2] tests/fetch: add test_git_submodule_branch_new_module
Date: Mon, 21 Aug 2017 21:37:40 +0500	[thread overview]
Message-ID: <20170821163741.28301-1-kergoth@gmail.com> (raw)

From: Christopher Larson <chris_larson@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@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



             reply	other threads:[~2017-08-21 16:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-21 16:37 Christopher Larson [this message]
2017-08-21 16:37 ` [PATCH 2/2] Revert "fetch2/gitsm: Fix when repository change submodules" Christopher Larson
2017-08-21 16:45   ` Christopher Larson
2017-08-21 16:57   ` [PATCHv2] fetch2/gitsm: copy submodules from DL_DIR in unpack Christopher Larson
2017-08-21 16:57     ` Christopher Larson
2017-08-23 10:22     ` Richard Purdie
2017-08-23 15:01       ` Christopher Larson
2017-08-23 16:53         ` Christopher Larson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170821163741.28301-1-kergoth@gmail.com \
    --to=kergoth@gmail.com \
    --cc=bitbake-devel@lists.openembedded.org \
    --cc=chris_larson@mentor.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.