diff --git a/fdroidserver/nightly.py b/fdroidserver/nightly.py index 3eb4333c..30161c1d 100644 --- a/fdroidserver/nightly.py +++ b/fdroidserver/nightly.py @@ -203,6 +203,15 @@ def get_repo_base_url(clone_url: str, repo_git_base: str, force_type: Optional[s sys.exit(1) +def clone_git_repo(clone_url, git_mirror_path): + logging.debug(_('cloning {url}').format(url=clone_url)) + vcs = common.getvcs('git', clone_url, git_mirror_path) + p = vcs.git(['clone', '--', vcs.remote, str(vcs.local)]) + if p.returncode != 0: + print('WARNING: only public git repos are supported!') + raise VCSException('git clone %s failed:' % clone_url, p.output) + + def main(): """Deploy to F-Droid repository or generate SSH private key from keystore. @@ -338,12 +347,7 @@ def main(): git_mirror_repodir = os.path.join(git_mirror_fdroiddir, 'repo') git_mirror_metadatadir = os.path.join(git_mirror_fdroiddir, 'metadata') if not os.path.isdir(git_mirror_repodir): - logging.debug(_('cloning {url}').format(url=clone_url)) - vcs = common.getvcs('git', clone_url, git_mirror_path) - p = vcs.git(['clone', '--', vcs.remote, str(vcs.local)]) - if p.returncode != 0: - print('WARNING: only public git repos are supported!') - raise VCSException('git clone %s failed:' % clone_url, p.output) + clone_git_repo(clone_url, git_mirror_repodir) if not os.path.isdir(git_mirror_repodir): os.makedirs(git_mirror_repodir, mode=0o755) diff --git a/tests/test_nightly.py b/tests/test_nightly.py index 750a22fc..681df96d 100755 --- a/tests/test_nightly.py +++ b/tests/test_nightly.py @@ -192,6 +192,29 @@ class NightlyTest(unittest.TestCase): with self.assertRaises(exception.VCSException): nightly.main() + def test_clone_git_repo(self): + os.chdir(self.testdir) + common.options = Options + d = 'fakeappid' + nightly.clone_git_repo('https://gitlab.com/fdroid/ci-test-tiny-repo.git', d) + self.assertTrue(os.path.isdir(Path(d) / '.git')) + + def test_clone_git_repo_fails_on_gitlab_password_prompt(self): + os.chdir(self.testdir) + common.options = Options + d = 'shouldnotbecreated' + with self.assertRaises(exception.VCSException): + nightly.clone_git_repo(f'https://gitlab.com/{d}/{d}.git', d) + self.assertFalse(os.path.isdir(Path(d))) + + def test_clone_git_repo_fails_on_github_password_prompt(self): + os.chdir(self.testdir) + common.options = Options + d = 'shouldnotbecreated' + with self.assertRaises(exception.VCSException): + nightly.clone_git_repo(f'https://github.com/{d}/{d}.git', d) + self.assertFalse(os.path.isdir(Path(d))) + def _put_fdroid_in_args(self, args): """Find fdroid command that belongs to this source code tree""" fdroid = os.path.join(basedir.parent, 'fdroid')