2
0
mirror of https://github.com/frappe/bench.git synced 2024-06-30 21:03:29 +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
: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):