fix: index only mode setting doesn't work if it follows a full mode config

This commit is contained in:
proletarius101 2024-04-06 15:13:58 +08:00
parent 96d1f4190f
commit d2ada6e418
No known key found for this signature in database
1 changed files with 16 additions and 4 deletions

View File

@ -25,7 +25,7 @@ import re
import subprocess
import time
import urllib
from git import Optional
from typing import Optional
import yaml
from argparse import ArgumentParser, Namespace
import logging
@ -503,11 +503,22 @@ def update_servergitmirrors(servergitmirrors, repo_section):
progress = None
repo = git.Repo.init(git_mirror_path, initial_branch=GIT_BRANCH)
initial_commit_ref = repo.head.commit
# An initial commit of the git tree is required be for other operations
initial_branch_ref = repo.head.ref
repo.index.commit('Initial commit')
enabled_remotes = []
for d in servergitmirrors:
index_only = d.get('index_only', False)
if index_only:
# Use a separate branch for the index only mode as it needs a different set of files to commit
repo.create_head('index_only', initial_branch_ref)
repo.heads.index_only.checkout()
else:
repo.create_head('full', initial_branch_ref)
repo.heads.full.checkout()
remote_url = d['url']
name = REMOTE_HOSTNAME_REGEX.sub(r'\1', remote_url)
enabled_remotes.append(name)
@ -586,8 +597,9 @@ def update_servergitmirrors(servergitmirrors, repo_section):
else:
logging.debug(remote.url + ': ' + pushinfo.summary)
# Reset the repository to the initial commit so we can choose which files to commit to the next remote
repo.head.reset(initial_commit_ref, index=True, working_tree=True)
# Switch to the initial branch
repo.head.reference = initial_branch_ref
repo.head.reset(index=True, working_tree=True)
if progress:
progressbar.done()