2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-12 08:16:28 +00:00

Merge pull request #1306 from revant/fix-init-for-tag

fix: allow bench init with git tags
This commit is contained in:
gavin 2022-05-17 14:07:07 +05:30 committed by GitHub
commit 338df66e48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 15 deletions

View File

@ -35,6 +35,7 @@ class TestUtils(unittest.TestCase):
is_valid_frappe_branch("https://github.com/random/random.git", frappe_branch="random-branch")
is_valid_frappe_branch("https://github.com/frappe/frappe.git", frappe_branch="develop")
is_valid_frappe_branch("https://github.com/frappe/frappe.git", frappe_branch="v13.29.0")
def test_app_states(self):
bench_dir = "./sandbox"

View File

@ -50,6 +50,7 @@ def is_frappe_app(directory: str) -> bool:
return bool(is_frappe_app)
@lru_cache(maxsize=None)
def is_valid_frappe_branch(frappe_path:str, frappe_branch:str):
"""Check if a branch exists in a repo. Throws InvalidRemoteException if branch is not found
@ -61,26 +62,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",
)
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 or tag: {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):