diff --git a/readthedocs/rtd_tests/tests/test_backend.py b/readthedocs/rtd_tests/tests/test_backend.py index 976ff5685ee..724c2d56b29 100644 --- a/readthedocs/rtd_tests/tests/test_backend.py +++ b/readthedocs/rtd_tests/tests/test_backend.py @@ -78,6 +78,16 @@ def test_parse_git_tags(self): self.project.vcs_repo().parse_tags(data)] self.assertEqual(expected_tags, given_ids) + def test_check_for_submodules(self): + repo = self.project.vcs_repo() + + repo.checkout() + self.assertFalse(repo.submodules_exists()) + + # The submodule branch contains one submodule + repo.checkout('submodule') + self.assertTrue(repo.submodules_exists()) + class TestHgBackend(RTDTestCase): def setUp(self): diff --git a/readthedocs/rtd_tests/utils.py b/readthedocs/rtd_tests/utils.py index 5d4fc616f31..9223837eccb 100644 --- a/readthedocs/rtd_tests/utils.py +++ b/readthedocs/rtd_tests/utils.py @@ -34,6 +34,13 @@ def make_test_git(): log.info(check_output(['git', 'init'] + [directory], env=env)) log.info(check_output(['git', 'add', '.'], env=env)) log.info(check_output(['git', 'commit', '-m"init"'], env=env)) + # Add repo itself as submodule + log.info(check_output(['git', 'checkout', '-b', 'submodule'], env=env)) + log.info(check_output(['git', 'submodule', 'add', '-b', 'master', './', 'submodule'], env=env)) + log.info(check_output(['git', 'add', '.'], env=env)) + log.info(check_output(['git', 'commit', '-m"Add submodule"'], env=env)) + # Checkout to master branch again + log.info(check_output(['git', 'checkout', 'master'], env=env)) chdir(path) return directory diff --git a/readthedocs/vcs_support/backends/git.py b/readthedocs/vcs_support/backends/git.py index d2e623de1c6..77673907ec5 100644 --- a/readthedocs/vcs_support/backends/git.py +++ b/readthedocs/vcs_support/backends/git.py @@ -55,6 +55,10 @@ def repo_exists(self): code, _, _ = self.run('git', 'status', record=False) return code == 0 + def submodules_exists(self): + code, out, _ = self.run('git', 'submodule', 'status', record=False) + return code == 0 and bool(out) + def fetch(self): code, _, _ = self.run('git', 'fetch', '--tags', '--prune') if code != 0: @@ -187,9 +191,10 @@ def checkout(self, identifier=None): self.run('git', 'clean', '-d', '-f', '-f') # Update submodules - self.run('git', 'submodule', 'sync') - self.run('git', 'submodule', 'update', - '--init', '--recursive', '--force') + if self.submodules_exists(): + self.run('git', 'submodule', 'sync') + self.run('git', 'submodule', 'update', + '--init', '--recursive', '--force') return code, out, err