From d8fda90eedcee2cc39ba13b9f8f7b7bab37310c3 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 14 Feb 2020 00:24:38 -0500 Subject: repo: rework parser setup to handle `init -c` We added support for `repo init -c` to main.py, but not to the launcher, so the -c option only works after the first init has run which kind of defeats its purpose. Rework the parser setup so that we can tell it whether it's for "init" or "gitc-init" and then add the -c option in the same way we do in main.py. This has the benefit of getting the parser entirely out of the module scope which makes it a lot easier to reason about, and it means we can write some unittests. Change-Id: Icbc2ec3aceb938d5a8f941d5fbce1548553dc5f7 Test: repo help init Test: repo help gitc-init Test: repo init -u https://android.googlesource.com/platform/manifest -c Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255113 Reviewed-by: David Pursehouse Tested-by: Mike Frysinger --- tests/test_wrapper.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests/test_wrapper.py') diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py index 4d2cf3fb..a98c4130 100644 --- a/tests/test_wrapper.py +++ b/tests/test_wrapper.py @@ -66,6 +66,20 @@ class RepoWrapperUnitTest(RepoWrapperTestCase): self.assertEqual('', stderr.getvalue()) self.assertIn('repo launcher version', stdout.getvalue()) + def test_init_parser(self): + """Make sure 'init' GetParser works.""" + parser = self.wrapper.GetParser(gitc_init=False) + opts, args = parser.parse_args([]) + self.assertEqual([], args) + self.assertIsNone(opts.manifest_url) + + def test_gitc_init_parser(self): + """Make sure 'gitc-init' GetParser works.""" + parser = self.wrapper.GetParser(gitc_init=True) + opts, args = parser.parse_args([]) + self.assertEqual([], args) + self.assertIsNone(opts.manifest_file) + def test_get_gitc_manifest_dir_no_gitc(self): """ Test reading a missing gitc config file -- cgit v1.2.3-54-g00ecf