Skip to content

Commit

Permalink
Merge pull request frappe#1306 from revant/fix-init-for-tag
Browse files Browse the repository at this point in the history
fix: allow bench init with git tags
  • Loading branch information
gavindsouza authored May 17, 2022
2 parents f6a0471 + e7055fc commit 338df66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions bench/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_is_valid_frappe_branch(self):
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"
Expand Down
24 changes: 9 additions & 15 deletions bench/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 338df66

Please sign in to comment.