Skip to content

Commit ce01815

Browse files
committed
nightly: set up test for git clone function
1 parent d398994 commit ce01815

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

fdroidserver/nightly.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,15 @@ def get_repo_base_url(clone_url: str, repo_git_base: str, force_type: Optional[s
203203
sys.exit(1)
204204

205205

206+
def clone_git_repo(clone_url, git_mirror_path):
207+
logging.debug(_('cloning {url}').format(url=clone_url))
208+
vcs = common.getvcs('git', clone_url, git_mirror_path)
209+
p = vcs.git(['clone', '--', vcs.remote, str(vcs.local)])
210+
if p.returncode != 0:
211+
print('WARNING: only public git repos are supported!')
212+
raise VCSException('git clone %s failed:' % clone_url, p.output)
213+
214+
206215
def main():
207216
"""Deploy to F-Droid repository or generate SSH private key from keystore.
208217
@@ -338,12 +347,7 @@ def main():
338347
git_mirror_repodir = os.path.join(git_mirror_fdroiddir, 'repo')
339348
git_mirror_metadatadir = os.path.join(git_mirror_fdroiddir, 'metadata')
340349
if not os.path.isdir(git_mirror_repodir):
341-
logging.debug(_('cloning {url}').format(url=clone_url))
342-
vcs = common.getvcs('git', clone_url, git_mirror_path)
343-
p = vcs.git(['clone', '--', vcs.remote, str(vcs.local)])
344-
if p.returncode != 0:
345-
print('WARNING: only public git repos are supported!')
346-
raise VCSException('git clone %s failed:' % clone_url, p.output)
350+
clone_git_repo(clone_url, git_mirror_repodir)
347351
if not os.path.isdir(git_mirror_repodir):
348352
os.makedirs(git_mirror_repodir, mode=0o755)
349353

tests/test_nightly.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,29 @@ def test_private_or_non_existent_git_mirror(self):
192192
with self.assertRaises(exception.VCSException):
193193
nightly.main()
194194

195+
def test_clone_git_repo(self):
196+
os.chdir(self.testdir)
197+
common.options = Options
198+
d = 'fakeappid'
199+
nightly.clone_git_repo('https://gitlab.com/fdroid/ci-test-tiny-repo.git', d)
200+
self.assertTrue(os.path.isdir(Path(d) / '.git'))
201+
202+
def test_clone_git_repo_fails_on_gitlab_password_prompt(self):
203+
os.chdir(self.testdir)
204+
common.options = Options
205+
d = 'shouldnotbecreated'
206+
with self.assertRaises(exception.VCSException):
207+
nightly.clone_git_repo(f'https://gitlab.com/{d}/{d}.git', d)
208+
self.assertFalse(os.path.isdir(Path(d)))
209+
210+
def test_clone_git_repo_fails_on_github_password_prompt(self):
211+
os.chdir(self.testdir)
212+
common.options = Options
213+
d = 'shouldnotbecreated'
214+
with self.assertRaises(exception.VCSException):
215+
nightly.clone_git_repo(f'https://github.com/{d}/{d}.git', d)
216+
self.assertFalse(os.path.isdir(Path(d)))
217+
195218
def _put_fdroid_in_args(self, args):
196219
"""Find fdroid command that belongs to this source code tree"""
197220
fdroid = os.path.join(basedir.parent, 'fdroid')

0 commit comments

Comments
 (0)