From cb2b0b0d7cd38d68973981dcf4659751ddd1cb0f Mon Sep 17 00:00:00 2001 From: Aradhya Date: Sun, 15 May 2022 17:26:05 +0530 Subject: [PATCH] feat: using gitpython for branch validation --- bench/utils/__init__.py | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index 613a1b2d..0dbe5a08 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -61,35 +61,19 @@ def is_valid_frappe_branch(frappe_path:str, frappe_branch:str): :type frappe_branch: str :raises InvalidRemoteException: branch for this repo doesn't exist """ - import subprocess + import git + + g = git.cmd.Git() if frappe_branch: try: - ret = subprocess.check_output( - ( - "git", - "ls-remote", - "--heads", - frappe_path, - frappe_branch, - ), - encoding="UTF-8", - ) or subprocess.check_output( - ( - "git", - "ls-remote", - "--tags", - frappe_path, - frappe_branch, - ), - encoding="UTF-8", - ) - if not ret: + res = g.ls_remote("--heads", "--tags", frappe_path, frappe_branch) + if not res: raise InvalidRemoteException( - f"Invalid {frappe_branch} for the remote {frappe_path}" + f"Invalid branch: {frappe_branch} for the remote {frappe_path}" ) - except subprocess.CalledProcessError: - raise InvalidRemoteException(f"Invalid frappe path {frappe_path}") + except git.exc.GitCommandError: + raise InvalidRemoteException(f"Invalid frappe path: {frappe_path}") def log(message, level=0, no_log=False):