diff --git a/fdroidserver/deploy.py b/fdroidserver/deploy.py index 621fa34a..7d2c80f9 100644 --- a/fdroidserver/deploy.py +++ b/fdroidserver/deploy.py @@ -505,9 +505,21 @@ def update_servergitmirrors(servergitmirrors, repo_section): enabled_remotes = [] for d in servergitmirrors: + is_index_only = d.get('index_only', False) + + # Use a separate branch for the index only mode as it needs a different set of files to commit + if is_index_only: + local_branch_name = 'index_only' + else: + local_branch_name = 'full' + if local_branch_name in repo.heads: + repo.git.switch(local_branch_name) + else: + repo.git.switch('--orphan', local_branch_name) + # trailing slashes have a meaning in rsync which is not needed here, so # make sure both paths have exactly one trailing slash - if d.get('index_only', False): + if is_index_only: files_to_sync = [str(working_dir_root / repo_section / index_file) for index_file in INDEX_FILES] else: files_to_sync = [str(working_dir_root / repo_section).rstrip('/') + '/'] @@ -517,6 +529,7 @@ def update_servergitmirrors(servergitmirrors, repo_section): local_repo=repo, enabled_remotes=enabled_remotes, repo_section=repo_section, + is_index_only=is_index_only, fdroid_dir=git_fdroiddir, git_mirror_path=str(git_mirror_path), ssh_cmd=ssh_cmd, @@ -532,6 +545,7 @@ def upload_to_servergitmirror(mirror_config: Dict[str, str], local_repo: Repo, enabled_remotes: List[str], repo_section: str, + is_index_only: bool, fdroid_dir: str, git_mirror_path: str, ssh_cmd: str, @@ -542,18 +556,8 @@ def upload_to_servergitmirror(mirror_config: Dict[str, str], logging.info("files:") logging.info(local_repo.git.ls_files()) - index_only = mirror_config.get('index_only', False) - - # Use a separate branch for the index only mode as it needs a different set of files to commit - if index_only: - local_branch_name = 'index_only' - else: - local_branch_name = 'full' - if local_branch_name in local_repo.heads: - local_repo.git.switch(local_branch_name) - else: - local_repo.git.switch('--orphan', local_branch_name) remote_branch_name = GIT_BRANCH + local_branch_name = local_repo.active_branch.name remote_url = mirror_config['url'] name = REMOTE_HOSTNAME_REGEX.sub(r'\1', remote_url) @@ -568,7 +572,7 @@ def upload_to_servergitmirror(mirror_config: Dict[str, str], logging.info('Mirroring to: ' + remote_url) logging.info("git status:", local_repo.git.status()) - if index_only: + if is_index_only: # test logging.debug('Adding index files to git mirror') local_repo.index.add(_get_index_file_paths(os.path.join('fdroid', repo_section))) @@ -581,7 +585,7 @@ def upload_to_servergitmirror(mirror_config: Dict[str, str], local_repo.index.commit("fdroidserver git-mirror") # Test - logging.info(f"In index-only: {index_only} mode") + logging.info(f"In index-only: {is_index_only} mode") logging.info(local_repo.git.status()) logging.info(local_repo.head.log()) diff --git a/tests/deploy.TestCase b/tests/deploy.TestCase index 36263c68..1994b53c 100755 --- a/tests/deploy.TestCase +++ b/tests/deploy.TestCase @@ -1000,6 +1000,7 @@ class DeployTest(unittest.TestCase): local_repo=local_git_repo, enabled_remotes=enabled_remotes, repo_section=repo_section, + is_index_only=mirror_config['index_only'], fdroid_dir=str(fdroid_dir), git_mirror_path=str(local_git_repo_path), ssh_cmd=ssh_cmd,