diff --git a/bench/app.py b/bench/app.py index 4f74fc32c..7ec14047a 100755 --- a/bench/app.py +++ b/bench/app.py @@ -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) diff --git a/bench/bench.py b/bench/bench.py index 93a839568..3c7573496 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -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 @@ def set_states(self): 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 @@ def update_apps_states(self, app_name: str = None, resolution: str = None): 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, }