Skip to content

Commit

Permalink
fix: only fetch what is necessary, simplify & improve grepability
Browse files Browse the repository at this point in the history
  • Loading branch information
casesolved-co-uk committed Mar 17, 2021
1 parent 66240e1 commit 82173c1
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions bench/app.py
Expand Up @@ -228,7 +228,7 @@ def pull_apps(apps=None, bench_path='.', reset=False):
rebase = '--rebase' if get_config(bench_path).get('rebase_on_pull') else ''

apps = apps or get_apps(bench_path=bench_path)
# chech for local changes
# check for local changes
if not reset:
for app in apps:
excluded_apps = get_excluded_apps()
Expand Down Expand Up @@ -271,9 +271,10 @@ def pull_apps(apps=None, bench_path='.', reset=False):
reset_cmd = "git reset --hard {remote}/{branch}".format(
remote=remote, branch=get_current_branch(app,bench_path=bench_path))
if get_config(bench_path).get('shallow_clone'):
exec_cmd("git fetch --depth 1 --no-tags", cwd=app_dir)
exec_cmd("git fetch --depth=1 --no-tags", cwd=app_dir)
exec_cmd(reset_cmd, cwd=app_dir)
exec_cmd("git clean -dfx", cwd=app_dir)
exec_cmd("git reflog expire --all", cwd=app_dir)
exec_cmd("git gc --prune=all", cwd=app_dir)
else:
exec_cmd("git fetch --all", cwd=app_dir)
exec_cmd(reset_cmd, cwd=app_dir)
Expand All @@ -284,20 +285,15 @@ def pull_apps(apps=None, bench_path='.', reset=False):


def is_version_upgrade(app='frappe', bench_path='.', branch=None):
try:
fetch_upstream(app, bench_path=bench_path)
except CommandFailedError:
raise InvalidRemoteException("No remote named upstream for {0}".format(app))

upstream_version = get_upstream_version(app=app, branch=branch, bench_path=bench_path)

if not upstream_version:
raise InvalidBranchException("Specified branch of app {0} is not in upstream".format(app))
raise InvalidBranchException('Specified branch of app {0} is not in upstream remote'.format(app))

local_version = get_major_version(get_current_version(app, bench_path=bench_path))
upstream_version = get_major_version(upstream_version)

if upstream_version - local_version > 0:
if upstream_version > local_version:
return (True, local_version, upstream_version)

return (False, local_version, upstream_version)
Expand Down Expand Up @@ -330,10 +326,6 @@ def use_rq(bench_path):
celery_app = os.path.join(bench_path, 'apps', 'frappe', 'frappe', 'celery_app.py')
return not os.path.exists(celery_app)

def fetch_upstream(app, bench_path='.'):
repo_dir = get_repo_dir(app, bench_path=bench_path)
return subprocess.call(["git", "fetch", "upstream"], cwd=repo_dir)

def get_current_version(app, bench_path='.'):
repo_dir = get_repo_dir(app, bench_path=bench_path)
try:
Expand All @@ -352,10 +344,16 @@ def get_develop_version(app, bench_path='.'):

def get_upstream_version(app, branch=None, bench_path='.'):
repo_dir = get_repo_dir(app, bench_path=bench_path)
try:
subprocess.call('git fetch --depth=1 --no-tags upstream', shell=True, cwd=repo_dir)
except CommandFailedError:
raise InvalidRemoteException('Failed to fetch from remote named upstream for {0}'.format(app))

if not branch:
branch = get_current_branch(app, bench_path=bench_path)
try:
contents = subprocess.check_output(['git', 'show', 'upstream/{branch}:{app}/__init__.py'.format(branch=branch, app=app)], cwd=repo_dir, stderr=subprocess.STDOUT)
contents = subprocess.check_output('git show upstream/{branch}:{app}/__init__.py'.format(branch=branch, app=app),
shell=True, cwd=repo_dir, stderr=subprocess.STDOUT)
contents = contents.decode('utf-8')
except subprocess.CalledProcessError as e:
if b"Invalid object" in e.output:
Expand Down

0 comments on commit 82173c1

Please sign in to comment.