mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-02-23 05:35:44 -05:00
packages: fix up cmd_update(), {init,clone}_pkgbuilds()
This commit is contained in:
parent
d5c5d19c94
commit
c12b702383
2 changed files with 9 additions and 7 deletions
|
@ -58,11 +58,12 @@ cmd_packages.add_command(cmd_devices_list, 'devices')
|
||||||
|
|
||||||
@cmd_packages.command(name='update')
|
@cmd_packages.command(name='update')
|
||||||
@click.option('--non-interactive', is_flag=True)
|
@click.option('--non-interactive', is_flag=True)
|
||||||
def cmd_update(non_interactive: bool = False):
|
@click.option('--switch-branch', is_flag=True, help="Force the branch to be corrected even in non-interactive mode")
|
||||||
|
def cmd_update(non_interactive: bool = False, switch_branch: bool = False):
|
||||||
"""Update PKGBUILDs git repo"""
|
"""Update PKGBUILDs git repo"""
|
||||||
init_pkgbuilds(interactive=not non_interactive)
|
init_pkgbuilds(interactive=not non_interactive, lazy=False, update=True, switch_branch=switch_branch)
|
||||||
logging.info("Refreshing SRCINFO caches")
|
logging.info("Refreshing SRCINFO caches")
|
||||||
discover_pkgbuilds()
|
discover_pkgbuilds(lazy=False)
|
||||||
|
|
||||||
|
|
||||||
# alias "update" to "init"
|
# alias "update" to "init"
|
||||||
|
|
|
@ -19,7 +19,7 @@ from wrapper import check_programs_wrap
|
||||||
from .srcinfo_cache import SrcinfoMetaFile
|
from .srcinfo_cache import SrcinfoMetaFile
|
||||||
|
|
||||||
|
|
||||||
def clone_pkgbuilds(pkgbuilds_dir: str, repo_url: str, branch: str, interactive=False, update=True):
|
def clone_pkgbuilds(pkgbuilds_dir: str, repo_url: str, branch: str, interactive=False, update=True, switch_branch: bool = False):
|
||||||
check_programs_wrap(['git'])
|
check_programs_wrap(['git'])
|
||||||
git_dir = os.path.join(pkgbuilds_dir, '.git')
|
git_dir = os.path.join(pkgbuilds_dir, '.git')
|
||||||
if not os.path.exists(git_dir):
|
if not os.path.exists(git_dir):
|
||||||
|
@ -31,13 +31,14 @@ def clone_pkgbuilds(pkgbuilds_dir: str, repo_url: str, branch: str, interactive=
|
||||||
current_branch = git_get_branch(pkgbuilds_dir)
|
current_branch = git_get_branch(pkgbuilds_dir)
|
||||||
if current_branch != branch:
|
if current_branch != branch:
|
||||||
logging.warning(f'pkgbuilds repository is on the wrong branch: {current_branch}, requested: {branch}')
|
logging.warning(f'pkgbuilds repository is on the wrong branch: {current_branch}, requested: {branch}')
|
||||||
if interactive and click.confirm('Would you like to switch branches?', default=False):
|
if switch_branch or (interactive and click.confirm('Would you like to switch branches?', default=False)):
|
||||||
result = git(['remote', 'update'], dir=pkgbuilds_dir)
|
result = git(['remote', 'update'], dir=pkgbuilds_dir)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise Exception('failed updating PKGBUILDs branches')
|
raise Exception('failed updating PKGBUILDs branches')
|
||||||
result = git(['switch', branch], dir=pkgbuilds_dir)
|
result = git(['switch', branch], dir=pkgbuilds_dir)
|
||||||
if result.returncode != 0:
|
if result.returncode != 0:
|
||||||
raise Exception('failed switching PKGBUILDs branches')
|
raise Exception('failed switching PKGBUILDs branches')
|
||||||
|
|
||||||
if update:
|
if update:
|
||||||
if interactive:
|
if interactive:
|
||||||
if not click.confirm('Would you like to try updating the PKGBUILDs repo?'):
|
if not click.confirm('Would you like to try updating the PKGBUILDs repo?'):
|
||||||
|
@ -50,14 +51,14 @@ def clone_pkgbuilds(pkgbuilds_dir: str, repo_url: str, branch: str, interactive=
|
||||||
_pkgbuilds_initialised: bool = False
|
_pkgbuilds_initialised: bool = False
|
||||||
|
|
||||||
|
|
||||||
def init_pkgbuilds(interactive=False, lazy: bool = True):
|
def init_pkgbuilds(interactive=False, lazy: bool = True, update: bool = False, switch_branch: bool = False):
|
||||||
global _pkgbuilds_initialised
|
global _pkgbuilds_initialised
|
||||||
if lazy and _pkgbuilds_initialised:
|
if lazy and _pkgbuilds_initialised:
|
||||||
return
|
return
|
||||||
pkgbuilds_dir = config.get_path('pkgbuilds')
|
pkgbuilds_dir = config.get_path('pkgbuilds')
|
||||||
repo_url = config.file.pkgbuilds.git_repo
|
repo_url = config.file.pkgbuilds.git_repo
|
||||||
branch = config.file.pkgbuilds.git_branch
|
branch = config.file.pkgbuilds.git_branch
|
||||||
clone_pkgbuilds(pkgbuilds_dir, repo_url, branch, interactive=interactive, update=False)
|
clone_pkgbuilds(pkgbuilds_dir, repo_url, branch, interactive=interactive, update=update, switch_branch=switch_branch)
|
||||||
_pkgbuilds_initialised = True
|
_pkgbuilds_initialised = True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue