diff mbox series

[v2,3/3] oeqa/selftest/devtool: Add test for multiple nested git destsuffix repos

Message ID 20260522075925.2381158-4-jamin_lin@aspeedtech.com
State New
Headers show
Series devtool: fix standalone clone conversion for nested git repos | expand

Commit Message

Jamin Lin May 22, 2026, 7:59 a.m. UTC
Add test_devtool_modify_multi_git_destsuffix_standalone to verify that
devtool modify converts all nested git repos (from multiple SRC_URI git
entries with different destsuffix values) to standalone clones so the
workspace survives 'bitbake -c cleanall'.

Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
---
 meta/lib/oeqa/selftest/cases/devtool.py | 67 +++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/devtool.py b/meta/lib/oeqa/selftest/cases/devtool.py
index 5ed69aee1b..b927bbf8f0 100644
--- a/meta/lib/oeqa/selftest/cases/devtool.py
+++ b/meta/lib/oeqa/selftest/cases/devtool.py
@@ -1182,6 +1182,73 @@  class DevtoolModifyTests(DevtoolBase):
         self.assertExists(os.path.join(source_repo_gitsm_gitmodules, 'bitbake'), 'Submodule not found')
         self.assertExists(os.path.join(source_repo_gitsm_gitmodules, 'bitbake-gitsm-test1'), 'Submodule not found')
 
+    def test_devtool_modify_multi_git_destsuffix_standalone(self):
+        """
+        Verify that devtool modify converts all nested git repos (from multiple
+        SRC_URI git entries with different destsuffix values) to standalone clones
+        so that 'bitbake -c cleanall' does not break the devtool workspace.
+
+        The recipe (devtool-test-multi-destsuffix) has six git SRC_URI entries
+        with S = ${UNPACKDIR}. All repos are nested inside S:
+            destsuffix=level1_a              -> srcdir/level1_a/
+            destsuffix=level1_b              -> srcdir/level1_b/
+            destsuffix=level1/level2_a       -> srcdir/level1/level2_a/
+            destsuffix=level1/level2_b       -> srcdir/level1/level2_b/
+            destsuffix=level1/level2/level3_a -> srcdir/level1/level2/level3_a/
+            destsuffix=level1/level2/level3_b -> srcdir/level1/level2/level3_b/
+
+        This mirrors real-world recipes that embed multiple module repos
+        as nested subdirectories of the primary source tree.
+        """
+        testrecipe = 'devtool-test-multi-destsuffix'
+        src_uri = get_bb_var('SRC_URI', testrecipe)
+        self.assertIn('git://', src_uri,
+                      'This test expects %s to have git SRC_URI entries' % testrecipe)
+        self.track_for_cleanup(self.workspacedir)
+        self.add_command_to_tearDown('devtool reset %s' % testrecipe)
+        self.add_command_to_tearDown('bitbake-layers remove-layer */workspace')
+        result = runCmd('devtool modify %s' % testrecipe)
+        self.assertEqual(result.status, 0,
+                         'devtool modify failed: %s' % result.output)
+        srcdir = os.path.join(self.workspacedir, 'sources', testrecipe)
+        nested_paths = [
+            ('level1_a', 'level1_a'),
+            ('level1_b', 'level1_b'),
+            ('level2_a', 'level1/level2_a'),
+            ('level2_b', 'level1/level2_b'),
+            ('level3_a', 'level1/level2/level3_a'),
+            ('level3_b', 'level1/level2/level3_b'),
+        ]
+
+        for name, subpath in nested_paths:
+            repo_path = os.path.join(srcdir, subpath)
+            self.assertExists(os.path.join(repo_path, '.git'),
+                              'Repo %s (.git) not found in devtool workspace' % name)
+
+        # Key assertion: no nested repo should retain a git alternates file.
+        # devtool modify must repack objects locally so the workspace does not
+        # depend on the downloads cache, which 'bitbake -c cleanall' will delete.
+        for name, subpath in nested_paths:
+            repo_path = os.path.join(srcdir, subpath)
+            alternates_file = os.path.join(repo_path, '.git', 'objects',
+                                           'info', 'alternates')
+            self.assertNotExists(alternates_file,
+                                 'Repo %s still has a git alternates file after '
+                                 'devtool modify' % name)
+
+        # Verify the workspace survives cleanall, which removes the shared
+        # objects in the downloads cache that alternates would reference.
+        bitbake('%s -c cleanall' % testrecipe)
+
+        # After cleanall all repos must still be usable.
+        # A broken alternates file would cause git operations to fail.
+        for name, subpath in nested_paths:
+            repo_path = os.path.join(srcdir, subpath)
+            result = runCmd('git status', cwd=repo_path)
+            self.assertEqual(result.status, 0,
+                             'git status failed in repo %s after cleanall: %s'
+                             % (name, result.output))
+
 class DevtoolUpdateTests(DevtoolBase):
 
     def test_devtool_update_recipe(self):