mirror of
https://github.com/frappe/bench.git
synced 2024-11-11 15:51:03 +00:00
add shallow cloning, fix #8
This commit is contained in:
parent
99e0a41b88
commit
efd1cc4105
@ -1,5 +1,5 @@
|
|||||||
import os
|
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
|
import logging
|
||||||
|
|
||||||
@ -21,7 +21,8 @@ def add_to_appstxt(app, bench='.'):
|
|||||||
|
|
||||||
def get_app(app, git_url, bench='.'):
|
def get_app(app, git_url, bench='.'):
|
||||||
logger.info('getting app {}'.format(app))
|
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)
|
install_app(app, bench=bench)
|
||||||
|
|
||||||
def new_app(app, bench='.'):
|
def new_app(app, bench='.'):
|
||||||
|
@ -11,7 +11,8 @@ logger = logging.getLogger(__name__)
|
|||||||
default_config = {
|
default_config = {
|
||||||
'restart_supervisor_on_update': True,
|
'restart_supervisor_on_update': True,
|
||||||
'auto_update': True,
|
'auto_update': True,
|
||||||
'update_bench_on_update': True
|
'update_bench_on_update': True,
|
||||||
|
'shallow_clone': True
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_frappe(bench='.'):
|
def get_frappe(bench='.'):
|
||||||
@ -117,7 +118,7 @@ def get_config(bench='.'):
|
|||||||
|
|
||||||
def put_config(config, bench='.'):
|
def put_config(config, bench='.'):
|
||||||
with open(os.path.join(bench, 'config.json'), 'w') as f:
|
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='.'):
|
def update_config(new_config, bench='.'):
|
||||||
config = get_config(bench=bench)
|
config = get_config(bench=bench)
|
||||||
@ -145,3 +146,20 @@ def check_cmd(cmd, cwd='.'):
|
|||||||
return True
|
return True
|
||||||
except subprocess.CalledProcessError, e:
|
except subprocess.CalledProcessError, e:
|
||||||
return False
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user