mirror of
https://github.com/frappe/bench.git
synced 2025-02-03 19:38:24 +00:00
refactor(minor): switch branch
* Don't update node packages twice (already managed via update_requirements) * Don't reload bench.utils - this made sense back when bench was updated along with the apps * Fix utils namespaces. Import instead of ....
This commit is contained in:
parent
58e3d4931b
commit
747be65f92
@ -1,7 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from setuptools.config import read_configuration
|
from setuptools.config import read_configuration
|
||||||
import bench
|
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
from bench.exceptions import (
|
from bench.exceptions import (
|
||||||
@ -31,11 +30,10 @@ def is_version_upgrade(app="frappe", bench_path=".", branch=None):
|
|||||||
|
|
||||||
def switch_branch(branch, apps=None, bench_path=".", upgrade=False, check_upgrade=True):
|
def switch_branch(branch, apps=None, bench_path=".", upgrade=False, check_upgrade=True):
|
||||||
import git
|
import git
|
||||||
import importlib
|
from bench.utils import log, exec_cmd
|
||||||
from bench.utils.bench import (
|
from bench.utils.bench import (
|
||||||
build_assets,
|
build_assets,
|
||||||
update_requirements,
|
update_requirements,
|
||||||
update_node_packages,
|
|
||||||
patch_sites,
|
patch_sites,
|
||||||
post_upgrade,
|
post_upgrade,
|
||||||
)
|
)
|
||||||
@ -56,24 +54,22 @@ def switch_branch(branch, apps=None, bench_path=".", upgrade=False, check_upgrad
|
|||||||
app_dir = os.path.join(apps_dir, app)
|
app_dir = os.path.join(apps_dir, app)
|
||||||
|
|
||||||
if not os.path.exists(app_dir):
|
if not os.path.exists(app_dir):
|
||||||
bench.utils.log(f"{app} does not exist!", level=2)
|
log(f"{app} does not exist!", level=2)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
repo = git.Repo(app_dir)
|
repo = git.Repo(app_dir)
|
||||||
unshallow_flag = os.path.exists(os.path.join(app_dir, ".git", "shallow"))
|
unshallow_flag = os.path.exists(os.path.join(app_dir, ".git", "shallow"))
|
||||||
bench.utils.log(
|
log(f"Fetching upstream {'unshallow ' if unshallow_flag else ''}for {app}")
|
||||||
f"Fetching upstream {'unshallow ' if unshallow_flag else ''}for {app}"
|
|
||||||
)
|
|
||||||
|
|
||||||
bench.utils.exec_cmd("git remote set-branches upstream '*'", cwd=app_dir)
|
exec_cmd("git remote set-branches upstream '*'", cwd=app_dir)
|
||||||
bench.utils.exec_cmd(
|
exec_cmd(
|
||||||
f"git fetch --all{' --unshallow' if unshallow_flag else ''} --quiet", cwd=app_dir
|
f"git fetch --all{' --unshallow' if unshallow_flag else ''} --quiet", cwd=app_dir
|
||||||
)
|
)
|
||||||
|
|
||||||
if check_upgrade:
|
if check_upgrade:
|
||||||
version_upgrade = is_version_upgrade(app=app, bench_path=bench_path, branch=branch)
|
version_upgrade = is_version_upgrade(app=app, bench_path=bench_path, branch=branch)
|
||||||
if version_upgrade[0] and not upgrade:
|
if version_upgrade[0] and not upgrade:
|
||||||
bench.utils.log(
|
log(
|
||||||
f"Switching to {branch} will cause upgrade from"
|
f"Switching to {branch} will cause upgrade from"
|
||||||
f" {version_upgrade[1]} to {version_upgrade[2]}. Pass --upgrade to"
|
f" {version_upgrade[1]} to {version_upgrade[2]}. Pass --upgrade to"
|
||||||
" confirm",
|
" confirm",
|
||||||
@ -82,17 +78,15 @@ def switch_branch(branch, apps=None, bench_path=".", upgrade=False, check_upgrad
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print("Switching for " + app)
|
print("Switching for " + app)
|
||||||
bench.utils.exec_cmd(f"git checkout -f {branch}", cwd=app_dir)
|
exec_cmd(f"git checkout -f {branch}", cwd=app_dir)
|
||||||
|
|
||||||
if str(repo.active_branch) == branch:
|
if str(repo.active_branch) == branch:
|
||||||
switched_apps.append(app)
|
switched_apps.append(app)
|
||||||
else:
|
else:
|
||||||
bench.utils.log(f"Switching branches failed for: {app}", level=2)
|
log(f"Switching branches failed for: {app}", level=2)
|
||||||
|
|
||||||
if switched_apps:
|
if switched_apps:
|
||||||
bench.utils.log(
|
log(f"Successfully switched branches for: {', '.join(switched_apps)}", level=1)
|
||||||
"Successfully switched branches for: " + ", ".join(switched_apps), level=1
|
|
||||||
)
|
|
||||||
print(
|
print(
|
||||||
"Please run `bench update --patch` to be safe from any differences in"
|
"Please run `bench update --patch` to be safe from any differences in"
|
||||||
" database schema"
|
" database schema"
|
||||||
@ -100,8 +94,6 @@ def switch_branch(branch, apps=None, bench_path=".", upgrade=False, check_upgrad
|
|||||||
|
|
||||||
if version_upgrade[0] and upgrade:
|
if version_upgrade[0] and upgrade:
|
||||||
update_requirements()
|
update_requirements()
|
||||||
update_node_packages()
|
|
||||||
importlib.reload(bench.utils)
|
|
||||||
backup_all_sites()
|
backup_all_sites()
|
||||||
patch_sites()
|
patch_sites()
|
||||||
build_assets()
|
build_assets()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user