mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
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:
parent
99d8be9d2a
commit
545b35c0aa
@ -142,6 +142,28 @@ def parse_arguments():
|
|||||||
def subcommand_setup(_):
|
def subcommand_setup(_):
|
||||||
"""Disable default Apache2 Gitweb configuration."""
|
"""Disable default Apache2 Gitweb configuration."""
|
||||||
action_utils.webserver_disable('gitweb')
|
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):
|
def _clone_with_progress_report(url, repo_dir):
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class GitwebApp(app_module.App):
|
|||||||
|
|
||||||
app_id = 'gitweb'
|
app_id = 'gitweb'
|
||||||
|
|
||||||
_version = 1
|
_version = 2
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Create components for the app."""
|
"""Create components for the app."""
|
||||||
|
|||||||
@ -25,7 +25,7 @@ EXISTING_REPOS = [
|
|||||||
'owner': '',
|
'owner': '',
|
||||||
'access': 'public',
|
'access': 'public',
|
||||||
'is_private': False,
|
'is_private': False,
|
||||||
'default_branch': 'master',
|
'default_branch': 'main',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'something2',
|
'name': 'something2',
|
||||||
@ -33,7 +33,7 @@ EXISTING_REPOS = [
|
|||||||
'owner': '',
|
'owner': '',
|
||||||
'access': 'private',
|
'access': 'private',
|
||||||
'is_private': True,
|
'is_private': True,
|
||||||
'default_branch': 'master',
|
'default_branch': 'main',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -59,8 +59,8 @@ def action_run(*args, **kwargs):
|
|||||||
|
|
||||||
elif subcommand == 'get-branches':
|
elif subcommand == 'get-branches':
|
||||||
return json.dumps({
|
return json.dumps({
|
||||||
"default_branch": "master",
|
"default_branch": "main",
|
||||||
"branches": ["master", "branch1"]
|
"branches": ["main", "branch1"]
|
||||||
})
|
})
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@ -309,7 +309,7 @@ def test_edit_repository_failed_view(rf):
|
|||||||
'gitweb-name': 'something_other',
|
'gitweb-name': 'something_other',
|
||||||
'gitweb-description': 'test-description',
|
'gitweb-description': 'test-description',
|
||||||
'gitweb-owner': 'test-owner',
|
'gitweb-owner': 'test-owner',
|
||||||
'gitweb-default_branch': 'master',
|
'gitweb-default_branch': 'main',
|
||||||
}
|
}
|
||||||
request = rf.post(
|
request = rf.post(
|
||||||
urls.reverse('gitweb:edit',
|
urls.reverse('gitweb:edit',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user