utils: create git_get_branch() from packages.cli

This commit is contained in:
InsanePrawn 2022-09-22 06:02:37 +02:00
parent f395ef231b
commit daff20302a
2 changed files with 7 additions and 3 deletions

View file

@ -13,7 +13,7 @@ from constants import REPOSITORIES
from constants import Arch from constants import Arch
from distro.package import PackageInfo from distro.package import PackageInfo
from logger import setup_logging from logger import setup_logging
from utils import git from utils import git, git_get_branch
from wrapper import check_programs_wrap from wrapper import check_programs_wrap
from .srcinfo_cache import SrcinfoMetaFile from .srcinfo_cache import SrcinfoMetaFile
@ -28,8 +28,7 @@ def clone_pkgbuilds(pkgbuilds_dir: str, repo_url: str, branch: str, interactive=
if result.returncode != 0: if result.returncode != 0:
raise Exception('Error cloning pkgbuilds') raise Exception('Error cloning pkgbuilds')
else: else:
result = git(['--git-dir', git_dir, 'branch', '--show-current'], capture_output=True) current_branch = git_get_branch(pkgbuilds_dir)
current_branch = result.stdout.decode().strip()
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 interactive and click.confirm('Would you like to switch branches?', default=False):

View file

@ -79,6 +79,11 @@ def git(cmd: list[str], dir: Optional[str] = None, capture_output=False, user: O
return result return result
def git_get_branch(path) -> str:
result = git(['branch', '--show-current'], dir=path, capture_output=True)
return result.stdout.decode().strip()
def log_or_exception(raise_exception: bool, msg: str, exc_class=Exception, log_level=logging.WARNING): def log_or_exception(raise_exception: bool, msg: str, exc_class=Exception, log_level=logging.WARNING):
if raise_exception: if raise_exception:
raise exc_class(msg) raise exc_class(msg)