gitweb: Switch default branch name to main for new repositories

I tested additionally that if the root user has already configured
default branch other than main, it is not changed by the gitweb app
setup process.

Signed-off-by: Veiko Aasa <veiko17@disroot.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Veiko Aasa authored and James Valleroy committed 2022-07-15 20:54:32 -04:00
1 parent 99d8be9d2a
commit 545b35c0aa
3 files changed
+28 -6

No files matched your search

+22
View File
@@ -142,6 +142,28 @@ def parse_arguments():
def subcommand_setup(_):
"""Disable default Apache2 Gitweb configuration."""
action_utils.webserver_disable('gitweb')
if not _get_global_default_branch():
_set_global_default_branch('main')
def _get_global_default_branch():
"""Get globally configured default branch name."""
try:
default_branch = subprocess.check_output(
['git', 'config', '--global', '--get',
'init.defaultBranch']).decode().strip()
except subprocess.CalledProcessError as exception:
if exception.returncode == 1: # Default branch not configured
return None
raise
return default_branch
def _set_global_default_branch(name):
"""Configure default branch name globally."""
subprocess.check_call(
['git', 'config', '--global', 'init.defaultBranch', name])
def _clone_with_progress_report(url, repo_dir):