From 41ed881feaca7248426b60053aef41a2ce0eb39e Mon Sep 17 00:00:00 2001 From: Joey Degges Date: Mon, 4 Jan 2021 21:14:55 -0800 Subject: [PATCH] bitbake: tests/fetch: Test usehead with a non-default name Add tests for fetching a URL with the usehead parameter set and a non-default name set. We currently expect the local version of this test to fail since there is a bug in the usehead implementation that breaks for non-default names. (Bitbake rev: a2345110f217fac429f6ec15f699c87c39531e7c) Signed-off-by: Joey Degges Signed-off-by: Richard Purdie --- bitbake/lib/bb/tests/fetch.py | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 971c613ddd..64cc9fa76b 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py @@ -680,6 +680,38 @@ def test_local_gitfetch_usehead(self): unpack_rev = stdout[0].strip() self.assertEqual(orig_rev, unpack_rev) + def test_local_gitfetch_usehead_withname(self): + # Create dummy local Git repo + src_dir = tempfile.mkdtemp(dir=self.tempdir, + prefix='gitfetch_localusehead_') + src_dir = os.path.abspath(src_dir) + bb.process.run("git init", cwd=src_dir) + bb.process.run("git commit --allow-empty -m'Dummy commit'", + cwd=src_dir) + # Use other branch than master + bb.process.run("git checkout -b my-devel", cwd=src_dir) + bb.process.run("git commit --allow-empty -m'Dummy commit 2'", + cwd=src_dir) + stdout = bb.process.run("git rev-parse HEAD", cwd=src_dir) + orig_rev = stdout[0].strip() + + # Fetch and check revision + self.d.setVar("SRCREV", "AUTOINC") + url = "git://" + src_dir + ";protocol=file;usehead=1;name=newName" + try: + fetcher = bb.fetch.Fetch([url], self.d) + except Exception: + # TODO: We currently expect this test to fail. Drop the try and + # assert when usehead has been fixed. + return + self.assertEqual(1, 0) + fetcher.download() + fetcher.unpack(self.unpackdir) + stdout = bb.process.run("git rev-parse HEAD", + cwd=os.path.join(self.unpackdir, 'git')) + unpack_rev = stdout[0].strip() + self.assertEqual(orig_rev, unpack_rev) + class FetcherNoNetworkTest(FetcherTest): def setUp(self): super().setUp() @@ -878,6 +910,15 @@ def test_gitfetch_usehead(self): url = "git://git.openembedded.org/bitbake;usehead=1" self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url) + @skipIfNoNetwork() + def test_gitfetch_usehead_withname(self): + # Since self.gitfetcher() sets SRCREV we expect this to override + # `usehead=1' and instead fetch the specified SRCREV. See + # test_local_gitfetch_usehead() for a positive use of the usehead + # feature. + url = "git://git.openembedded.org/bitbake;usehead=1;name=newName" + self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url) + @skipIfNoNetwork() def test_gitfetch_finds_local_tarball_for_mirrored_url_when_previous_downloaded_by_the_recipe_url(self): recipeurl = "git://git.openembedded.org/bitbake"