From 0e3bd6f63e9406877d3084d6a3be57df2a462fa0 Mon Sep 17 00:00:00 2001 From: proletarius101 Date: Sun, 2 Jun 2024 19:31:13 +0800 Subject: [PATCH] fix(deploy): files are not pushed to the remote --- fdroidserver/deploy.py | 15 +++++++-------- tests/deploy.TestCase | 38 ++++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/fdroidserver/deploy.py b/fdroidserver/deploy.py index 548539f5..cdfa7222 100644 --- a/fdroidserver/deploy.py +++ b/fdroidserver/deploy.py @@ -730,12 +730,13 @@ def upload_to_servergitmirror(mirror_config: Dict[str, str], # Use a separate branch for the index only mode as it needs a different set of files to commit if index_only: - branch_name = 'index_only' + local_branch_name = 'index_only' else: - branch_name = 'full' - if branch_name not in local_repo.heads: - local_repo.create_head(branch_name) - local_repo.head.reference = local_repo.heads[branch_name] + local_branch_name = 'full' + if local_branch_name not in local_repo.heads: + local_repo.create_head(local_branch_name) + local_repo.head.reference = local_repo.heads[local_branch_name] + remote_branch_name = GIT_BRANCH remote_url = mirror_config['url'] name = REMOTE_HOSTNAME_REGEX.sub(r'\1', remote_url) @@ -751,8 +752,6 @@ def upload_to_servergitmirror(mirror_config: Dict[str, str], if index_only: # test - print(glob.glob('.' + '/**/*', recursive=True)) - logging.debug('Adding index files to git mirror') local_repo.index.add(_get_index_file_paths(os.path.join('fdroid', repo_section))) else: @@ -807,7 +806,7 @@ def upload_to_servergitmirror(mirror_config: Dict[str, str], logging.debug(_('Pushing to {url}').format(url=remote.url)) with local_repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd): pushinfos = remote.push( - GIT_BRANCH, force=True, set_upstream=True, progress=progress + f"{local_branch_name}:{remote_branch_name}", force=True, set_upstream=True, progress=progress ) for pushinfo in pushinfos: if pushinfo.flags & (git.remote.PushInfo.ERROR diff --git a/tests/deploy.TestCase b/tests/deploy.TestCase index be8b6a67..2df20aae 100755 --- a/tests/deploy.TestCase +++ b/tests/deploy.TestCase @@ -1028,14 +1028,14 @@ class DeployTest(unittest.TestCase): os.chdir(self.testdir) - local_repo_path = Path(self.testdir) / 'local' - local_repo = git.Repo.init( - local_repo_path, initial_branch=initial_branch + local_git_repo_path = Path(self.testdir) / 'local' + local_git_repo = git.Repo.init( + local_git_repo_path, initial_branch=initial_branch ) # An initial commit of the git tree is required be for other operations - local_repo.index.commit('Initial commit') + local_git_repo.index.commit('Initial commit') - fdroid_dir = local_repo_path / 'fdroid' + fdroid_dir = local_git_repo_path / 'fdroid' repo_dir = fdroid_dir / repo_section repo_dir.mkdir(parents=True) for filename in fdroidserver.deploy.INDEX_FILES: @@ -1044,23 +1044,37 @@ class DeployTest(unittest.TestCase): fp.write('not a real one, but has the right filename') # The remote repo must be a bare repo to allow being pushed to - remote_repo_path = Path(self.testdir) / 'remote' - remote_repo = git.Repo.init(remote_repo_path, initial_branch=initial_branch, bare=True) + remote_git_repo_dir = Path(self.testdir) / 'remote' + remote_git_repo = git.Repo.init( + remote_git_repo_dir, initial_branch=initial_branch, bare=True + ) - mirror_config = {"url": str(remote_repo_path), "index_only": True} + mirror_config = {"url": str(remote_git_repo_dir), "index_only": True} enabled_remotes = [] ssh_cmd = 'ssh -oBatchMode=yes' fdroidserver.deploy.upload_to_servergitmirror( mirror_config=mirror_config, - local_repo=local_repo, + local_repo=local_git_repo, enabled_remotes=enabled_remotes, repo_section=repo_section, fdroid_dir=str(fdroid_dir), - git_mirror_path=str(local_repo_path), + git_mirror_path=str(local_git_repo_path), ssh_cmd=ssh_cmd, - progress=git.RemoteProgress() + progress=git.RemoteProgress(), ) - assert remote_repo.is_dirty + + verify_repo = remote_git_repo.clone( + Path(self.testdir) / 'verify', + ) + + for filename in fdroidserver.deploy.INDEX_FILES: + remote_file = f"fdroid/{repo_section}/{filename}" + + self.assertIsNotNone(verify_repo.working_tree_dir) + if verify_repo.working_tree_dir is not None: + self.assertTrue( + (Path(verify_repo.working_tree_dir) / remote_file).exists() + ) if __name__ == "__main__":