diff --git a/bench/app.py b/bench/app.py index f675f3a3..90c096ed 100644 --- a/bench/app.py +++ b/bench/app.py @@ -1,5 +1,5 @@ import os -from .utils import exec_cmd, get_frappe +from .utils import exec_cmd, get_frappe, check_git_for_shallow_clone, get_config import logging @@ -21,7 +21,8 @@ def add_to_appstxt(app, bench='.'): def get_app(app, git_url, bench='.'): logger.info('getting app {}'.format(app)) - exec_cmd("git clone {} --origin upstream {}".format(git_url, app), cwd=os.path.join(bench, 'apps')) + shallow_clone = '--depth 1' if check_git_for_shallow_clone() and get_config().get('shallow_clone') else '' + exec_cmd("git clone {git_url} {shallow_clone} --origin upstream {app}".format(git_url=git_url, app=app, shallow_clone=shallow_clone), cwd=os.path.join(bench, 'apps')) install_app(app, bench=bench) def new_app(app, bench='.'): diff --git a/bench/utils.py b/bench/utils.py index 2bde4d9d..a9b19d13 100644 --- a/bench/utils.py +++ b/bench/utils.py @@ -11,7 +11,8 @@ logger = logging.getLogger(__name__) default_config = { 'restart_supervisor_on_update': True, 'auto_update': True, - 'update_bench_on_update': True + 'update_bench_on_update': True, + 'shallow_clone': True } def get_frappe(bench='.'): @@ -117,7 +118,7 @@ def get_config(bench='.'): def put_config(config, bench='.'): with open(os.path.join(bench, 'config.json'), 'w') as f: - return json.dump(config, f) + return json.dump(config, f, indent=1) def update_config(new_config, bench='.'): config = get_config(bench=bench) @@ -145,3 +146,20 @@ def check_cmd(cmd, cwd='.'): return True except subprocess.CalledProcessError, e: return False + +def get_git_version(): + version = get_cmd_output("git --version") + return version.strip().split()[-1] + +def check_git_for_shallow_clone(): + git_version = get_git_version() + if '1.9' in git_version or '2.0' in git_version: + return True + return False + +def get_cmd_output(cmd, cwd='.'): + try: + return subprocess.check_output(cmd, cwd=cwd, shell=True) + except subprocess.CalledProcessError, e: + print "Error:", e.output + raise