deploy: ensure mirrors and binary transparency always create 'master'

If there was a global default on a machine that was something other than
'master', these things would crash with:

Traceback (most recent call last):
  File "/home/hans/code/fdroid/server/fdroid", line 22, in <module>
    fdroidserver.__main__.main()
  File "/home/hans/code/fdroid/server/fdroidserver/__main__.py", line 230, in main
    raise e
  File "/home/hans/code/fdroid/server/fdroidserver/__main__.py", line 211, in main
    mod.main()
  File "/home/hans/code/fdroid/server/fdroidserver/deploy.py", line 833, in main
    push_binary_transparency(BINARY_TRANSPARENCY_DIR,
  File "/home/hans/code/fdroid/server/fdroidserver/deploy.py", line 705, in push_binary_transparency
    local.pull('master')
  File "/usr/lib/python3/dist-packages/git/remote.py", line 1045, in pull
    res = self._get_fetch_info_from_stderr(proc, progress, kill_after_timeout=kill_after_timeout)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/git/remote.py", line 848, in _get_fetch_info_from_stderr
    proc.wait(stderr=stderr_text)
  File "/usr/lib/python3/dist-packages/git/cmd.py", line 604, in wait
    raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git pull -v -- local master
  stderr: 'fatal: couldn't find remote ref master'
This commit is contained in:
Hans-Christoph Steiner 2023-05-09 20:09:28 +02:00
parent 0735bfa7e5
commit f7830a41f1
4 changed files with 17 additions and 9 deletions

View File

@ -125,6 +125,10 @@ ubuntu_lts_ppa:
- apt-get update
- apt-get dist-upgrade
- apt-get install --install-recommends dexdump fdroidserver git jq python3-setuptools sdkmanager
# Test things work with a default branch other than 'master'
- git config --global init.defaultBranch thisisnotmasterormain
- cd tests
- ./run-tests

View File

@ -65,7 +65,7 @@ def make_binary_transparency_log(
else:
if not os.path.exists(btrepo):
os.mkdir(btrepo)
gitrepo = git.Repo.init(btrepo)
gitrepo = git.Repo.init(btrepo, initial_branch=deploy.GIT_BRANCH)
if not url:
url = common.config['repo_url'].rstrip('/')

View File

@ -39,6 +39,8 @@ config = None
options = None
start_timestamp = time.gmtime()
GIT_BRANCH = 'master'
BINARY_TRANSPARENCY_DIR = 'binary_transparency'
AUTO_S3CFG = '.fdroid-deploy-s3cfg'
@ -407,7 +409,7 @@ def update_servergitmirrors(servergitmirrors, repo_section):
elif 'identity_file' in config:
ssh_cmd += ' -oIdentitiesOnly=yes -i "%s"' % config['identity_file']
repo = git.Repo.init(git_mirror_path)
repo = git.Repo.init(git_mirror_path, initial_branch=GIT_BRANCH)
enabled_remotes = []
for remote_url in servergitmirrors:
@ -480,7 +482,9 @@ def update_servergitmirrors(servergitmirrors, repo_section):
logging.debug(_('Pushing to {url}').format(url=remote.url))
with repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd):
pushinfos = remote.push('master', force=True, set_upstream=True, progress=progress)
pushinfos = remote.push(
GIT_BRANCH, force=True, set_upstream=True, progress=progress
)
for pushinfo in pushinfos:
if pushinfo.flags & (git.remote.PushInfo.ERROR
| git.remote.PushInfo.REJECTED
@ -691,7 +695,7 @@ def push_binary_transparency(git_repo_path, git_remote):
remote_path = os.path.abspath(git_repo_path)
if not os.path.isdir(os.path.join(git_remote, '.git')):
os.makedirs(git_remote, exist_ok=True)
thumbdriverepo = git.Repo.init(git_remote)
thumbdriverepo = git.Repo.init(git_remote, initial_branch=GIT_BRANCH)
local = thumbdriverepo.create_remote('local', remote_path)
else:
thumbdriverepo = git.Repo(git_remote)
@ -702,7 +706,7 @@ def push_binary_transparency(git_repo_path, git_remote):
local.set_url(remote_path)
else:
local = thumbdriverepo.create_remote('local', remote_path)
local.pull('master')
local.pull(GIT_BRANCH)
else:
# from online machine to remote on a server on the internet
gitrepo = git.Repo(git_repo_path)
@ -713,7 +717,7 @@ def push_binary_transparency(git_repo_path, git_remote):
origin.set_url(git_remote)
else:
origin = gitrepo.create_remote('origin', git_remote)
origin.push('master')
origin.push(GIT_BRANCH)
def main():

View File

@ -1129,7 +1129,7 @@ echo_header "setup a new repo from scratch using ANDROID_HOME with git mirror"
# fake git remote server for repo mirror
SERVER_GIT_MIRROR=`create_test_dir`
cd $SERVER_GIT_MIRROR
$git init
$git init --initial-branch=master
$git config receive.denyCurrentBranch updateInstead
REPOROOT=`create_test_dir`
@ -1191,7 +1191,7 @@ SERVERWEBROOT=`create_test_dir`/fdroid
cd $OFFLINE_ROOT
mkdir binary_transparency
cd binary_transparency
$git init
$git init --initial-branch=master
# fake git remote server for binary transparency log
BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
@ -1199,7 +1199,7 @@ BINARY_TRANSPARENCY_REMOTE=`create_test_dir`
# fake git remote server for repo mirror
SERVER_GIT_MIRROR=`create_test_dir`
cd $SERVER_GIT_MIRROR
$git init
$git init --initial-branch=master
$git config receive.denyCurrentBranch updateInstead
cd $OFFLINE_ROOT