1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-09-21 04:10:37 +02:00

fix(deploy): files are not pushed to the remote

This commit is contained in:
proletarius101 2024-06-02 19:31:13 +08:00
parent 04c191e4d8
commit cd2a0fbf29
No known key found for this signature in database
2 changed files with 33 additions and 20 deletions

View File

@ -546,12 +546,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)
@ -567,8 +568,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:
@ -623,7 +622,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

View File

@ -972,14 +972,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:
@ -988,23 +988,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__":