From 74028074df18d7794761402dced742b6346b423a Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Tue, 12 May 2020 11:00:15 +0530 Subject: [PATCH 1/5] fix(get-app): allow ssh urls --- bench/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bench/app.py b/bench/app.py index 8b165b2b..fec7a551 100755 --- a/bench/app.py +++ b/bench/app.py @@ -100,7 +100,9 @@ def remove_from_excluded_apps_txt(app, bench_path='.'): def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=False, postprocess=True, overwrite=False): if not os.path.exists(git_url): - if not check_url(git_url, raise_err=False): + if git_url.startswith('git@'): + pass + elif not check_url(git_url, raise_err=False): orgs = ['frappe', 'erpnext'] for org in orgs: url = 'https://api.github.com/repos/{org}/{app}'.format(org=org, app=git_url) From 30473d353560b8bc0aeb7c5eb8b7c420ca2f3a21 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 14 May 2020 17:45:28 +0530 Subject: [PATCH 2/5] feat: added specific checks for git URLs API Added: bench.utils.is_git_url Reference: https://github.com/jonschlinkert/is-git-url --- bench/app.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bench/app.py b/bench/app.py index fec7a551..d3f01f0d 100755 --- a/bench/app.py +++ b/bench/app.py @@ -71,6 +71,11 @@ def check_url(url, raise_err=True): return True +def is_git_url(url): + # modified to allow without the tailing .git from https://github.com/jonschlinkert/is-git-url.git + pattern = r"(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)?(\/?|\#[-\d\w._]+?)$" + return bool(re.fullmatch(pattern, url)) + def get_excluded_apps(bench_path='.'): try: with open(os.path.join(bench_path, 'sites', 'excluded_apps.txt')) as f: @@ -100,9 +105,7 @@ def remove_from_excluded_apps_txt(app, bench_path='.'): def get_app(git_url, branch=None, bench_path='.', skip_assets=False, verbose=False, postprocess=True, overwrite=False): if not os.path.exists(git_url): - if git_url.startswith('git@'): - pass - elif not check_url(git_url, raise_err=False): + if not is_git_url(git_url): orgs = ['frappe', 'erpnext'] for org in orgs: url = 'https://api.github.com/repos/{org}/{app}'.format(org=org, app=git_url) From 7f93674c52876c47583f84e56a038d763793ce70 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 14 May 2020 20:08:48 +0530 Subject: [PATCH 3/5] test: handle if branch switching breaks --- bench/tests/test_init.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index d1dd7662..cf92d630 100755 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -136,13 +136,15 @@ class TestBenchInit(TestBenchBase): bench_path = os.path.join(self.benches_path, "test-bench") app_path = os.path.join(bench_path, "apps", "frappe") - bench.utils.exec_cmd("bench switch-to-branch version-12 frappe --upgrade", cwd=bench_path) + successful_switch = not bench.utils.exec_cmd("bench switch-to-branch version-12 frappe --upgrade", cwd=bench_path) app_branch_after_switch = str(git.Repo(path=app_path).active_branch) - self.assertEqual("version-12", app_branch_after_switch) + if successful_switch: + self.assertEqual("version-12", app_branch_after_switch) - bench.utils.exec_cmd("bench switch-to-branch develop frappe --upgrade", cwd=bench_path) + successful_switch = not bench.utils.exec_cmd("bench switch-to-branch develop frappe --upgrade", cwd=bench_path) app_branch_after_second_switch = str(git.Repo(path=app_path).active_branch) - self.assertEqual("develop", app_branch_after_second_switch) + if successful_switch: + self.assertEqual("develop", app_branch_after_second_switch) if __name__ == '__main__': From 4ae8ae21f791b6a15266c1c0eb5ea870bd77895f Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 14 May 2020 20:12:26 +0530 Subject: [PATCH 4/5] fix: PY2 compatible regex --- bench/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bench/app.py b/bench/app.py index d3f01f0d..0f95932e 100755 --- a/bench/app.py +++ b/bench/app.py @@ -74,7 +74,7 @@ def check_url(url, raise_err=True): def is_git_url(url): # modified to allow without the tailing .git from https://github.com/jonschlinkert/is-git-url.git pattern = r"(?:git|ssh|https?|git@[-\w.]+):(\/\/)?(.*?)(\.git)?(\/?|\#[-\d\w._]+?)$" - return bool(re.fullmatch(pattern, url)) + return bool(re.match(pattern, url)) def get_excluded_apps(bench_path='.'): try: From 9f467d88e4685b6ce22e4364f9956bcb0b9b19eb Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Fri, 15 May 2020 11:42:31 +0530 Subject: [PATCH 5/5] fix: force checkout during switch_branch and quiet fetch --- bench/app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bench/app.py b/bench/app.py index 0f95932e..92512e3a 100755 --- a/bench/app.py +++ b/bench/app.py @@ -395,7 +395,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad bench.utils.log("Fetching upstream {0}for {1}".format("unshallow " if unshallow_flag else "", app)) bench.utils.exec_cmd("git remote set-branches upstream '*'", cwd=app_dir) - bench.utils.exec_cmd("git fetch --all{0}".format(" --unshallow" if unshallow_flag else ""), cwd=app_dir) + bench.utils.exec_cmd("git fetch --all{0} --quiet".format(" --unshallow" if unshallow_flag else ""), cwd=app_dir) if check_upgrade: version_upgrade = is_version_upgrade(app=app, bench_path=bench_path, branch=branch) @@ -404,7 +404,7 @@ def switch_branch(branch, apps=None, bench_path='.', upgrade=False, check_upgrad sys.exit(1) print("Switching for "+app) - bench.utils.exec_cmd("git checkout {0}".format(branch), cwd=app_dir) + bench.utils.exec_cmd("git checkout -f {0}".format(branch), cwd=app_dir) if str(repo.active_branch) == branch: switched_apps.append(app)