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

Merge pull request #995 from gavindsouza/get-app-allow-ssh

This commit is contained in:
Chinmay Pai 2020-05-20 16:50:34 +05:30 committed by GitHub
commit 57f138b314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -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.match(pattern, url))
def get_excluded_apps(bench_path='.'):
try:
with open(os.path.join(bench_path, 'sites', 'excluded_apps.txt')) as f:
@ -100,7 +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 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)
@ -390,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)
@ -399,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)

View File

@ -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__':