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

feat: add commit hash and branch in states.json

This commit is contained in:
saxenabhishek 2022-03-10 23:06:47 +05:30
parent d178b08abb
commit 9004e1dd6a
2 changed files with 22 additions and 5 deletions

View File

@ -428,7 +428,7 @@ def install_resolved_deps(
for repo_name, app in reversed(resolution.items()):
existing_dir, _ = check_existing_dir(bench_path, repo_name)
if existing_dir:
if bench.apps.states[repo_name]["resolution"] != app.tag:
if bench.apps.states[repo_name]["resolution"]["branch"] != app.tag:
click.secho(
f"Incompatible version of {repo_name} is already installed",
fg="yellow",
@ -500,7 +500,7 @@ def install_app(
bench.run("yarn install", cwd=app_path)
bench.apps.sync()
bench.apps.update_apps_states(app, tag)
bench.apps.update_apps_states(app, branch=tag)
if not skip_assets:
build_assets(bench_path=bench_path, app=app)

View File

@ -1,11 +1,12 @@
# imports - standard imports
import subprocess
import functools
import os
import shutil
import json
import sys
import logging
from typing import List, MutableSequence, TYPE_CHECKING
from typing import List, MutableSequence, TYPE_CHECKING, Union
# imports - module imports
import bench
@ -159,6 +160,7 @@ class BenchApps(MutableSequence):
def __init__(self, bench: Bench):
self.bench = bench
self.states_path = os.path.join(self.bench.name, "sites", "apps_states.json")
self.apps_path = os.path.join(self.bench.name, "apps")
self.initialize_apps()
self.set_states()
@ -169,7 +171,7 @@ class BenchApps(MutableSequence):
except FileNotFoundError:
self.states = {}
def update_apps_states(self, app_name: str = None, resolution: str = None):
def update_apps_states(self, app_name: Union[str, None] = None, branch: Union[str, None] = None):
apps_to_remove = []
for app in self.states:
if app not in self.apps:
@ -180,8 +182,23 @@ class BenchApps(MutableSequence):
if app_name:
version = get_current_version(app_name, self.bench.name)
app_dir = os.path.join(self.apps_path, app_name)
if not branch:
branch = (
subprocess
.check_output("git rev-parse --abbrev-ref HEAD", shell=True, cwd=app_dir)
.decode("utf-8")
.rstrip()
)
commit_hash = subprocess.check_output(f"git rev-parse {branch}", shell=True, cwd=app_dir).decode("utf-8").rstrip()
self.states[app_name] = {
"resolution": resolution,
"resolution": {
"commit_hash":commit_hash,
"branch": branch
},
"version": version,
}