2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-19 03:25:21 +00:00

feat: using gitpython for branch validation

This commit is contained in:
Aradhya 2022-05-15 17:26:05 +05:30
parent c943b30c66
commit cb2b0b0d7c

View File

@ -61,35 +61,19 @@ def is_valid_frappe_branch(frappe_path:str, frappe_branch:str):
:type frappe_branch: str :type frappe_branch: str
:raises InvalidRemoteException: branch for this repo doesn't exist :raises InvalidRemoteException: branch for this repo doesn't exist
""" """
import subprocess import git
g = git.cmd.Git()
if frappe_branch: if frappe_branch:
try: try:
ret = subprocess.check_output( res = g.ls_remote("--heads", "--tags", frappe_path, frappe_branch)
( if not res:
"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:
raise InvalidRemoteException( raise InvalidRemoteException(
f"Invalid {frappe_branch} for the remote {frappe_path}" f"Invalid branch: {frappe_branch} for the remote {frappe_path}"
) )
except subprocess.CalledProcessError: except git.exc.GitCommandError:
raise InvalidRemoteException(f"Invalid frappe path {frappe_path}") raise InvalidRemoteException(f"Invalid frappe path: {frappe_path}")
def log(message, level=0, no_log=False): def log(message, level=0, no_log=False):