From 0458faa502e9992a4305bfbb282fbee344d505bf Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 10 Mar 2021 23:35:44 -0500 Subject: manifest: allow toplevel project checkouts Re-allow checking out projects to the top of the repo client checkout. We add checks to prevent checking out files under .repo/ as that path is only managed by us, and projects cannot inject content or settings into it. Bug: https://crbug.com/gerrit/14156 Bug: https://crbug.com/gerrit/14200 Change-Id: Id6bf9e882f5be748442b2c35bbeaee3549410b25 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/299623 Reviewed-by: Michael Mortensen Tested-by: Mike Frysinger --- tests/test_manifest_xml.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'tests/test_manifest_xml.py') diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 9060ef3d..eda06968 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py @@ -32,6 +32,7 @@ INVALID_FS_PATHS = ( '..', '../', './', + './/', 'foo/', './foo', '../foo', @@ -427,6 +428,28 @@ class ProjectElementTests(ManifestParseTestCase): self.assertEqual(manifest.projects[0].objdir, os.path.join(self.tempdir, '.repo/project-objects/a/path.git')) + manifest = parse('a/path', 'foo//////') + self.assertEqual(manifest.projects[0].gitdir, + os.path.join(self.tempdir, '.repo/projects/foo.git')) + self.assertEqual(manifest.projects[0].objdir, + os.path.join(self.tempdir, '.repo/project-objects/a/path.git')) + + def test_toplevel_path(self): + """Check handling of path=. specially.""" + def parse(name, path): + return self.getXmlManifest(f""" + + + + + +""") + + for path in ('.', './', './/', './//'): + manifest = parse('server/path', path) + self.assertEqual(manifest.projects[0].gitdir, + os.path.join(self.tempdir, '.repo/projects/..git')) + def test_bad_path_name_checks(self): """Check handling of bad path & name attributes.""" def parse(name, path): @@ -454,8 +477,11 @@ class ProjectElementTests(ManifestParseTestCase): with self.assertRaises(error.ManifestInvalidPathError): parse(path, 'ok') - with self.assertRaises(error.ManifestInvalidPathError): - parse('ok', path) + + # We have a dedicated test for path=".". + if path not in {'.'}: + with self.assertRaises(error.ManifestInvalidPathError): + parse('ok', path) class SuperProjectElementTests(ManifestParseTestCase): -- cgit v1.2.3-54-g00ecf