Skip to content

Commit

Permalink
Checked new updates within git branch (#533)
Browse files Browse the repository at this point in the history
* Checked new updates within git branch

* Bugfix

* Bugfix

* Dummy commit

* Update cli/medperf/utils.py

Co-authored-by: hasan7n <[email protected]>

---------

Co-authored-by: hasan7n <[email protected]>
  • Loading branch information
VukW and hasan7n authored Feb 21, 2024
1 parent bad6bf1 commit 824c432
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/medperf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import medperf.commands.association.association as association
import medperf.commands.compatibility_test.compatibility_test as compatibility_test
import medperf.commands.storage as storage
from medperf.utils import check_for_updates

app = typer.Typer()
app.add_typer(mlcube.app, name="mlcube", help="Manage mlcubes")
Expand Down Expand Up @@ -99,5 +100,6 @@ def main(

logging.info(f"Running MedPerf v{__version__} on {loglevel} logging level")
logging.info(f"Executed command: {' '.join(sys.argv[1:])}")
check_for_updates()

config.ui.print(f"MedPerf {__version__}")
36 changes: 36 additions & 0 deletions cli/medperf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import List
from colorama import Fore, Style
from pexpect.exceptions import TIMEOUT
from git import Repo, GitCommandError
import medperf.config as config
from medperf.exceptions import ExecutionError, MedperfException, InvalidEntityError

Expand Down Expand Up @@ -438,6 +439,41 @@ def filter_latest_associations(associations, entity_key):
return latest_associations


def check_for_updates() -> None:
"""Check if the current branch is up-to-date with its remote counterpart using GitPython."""
repo = Repo(config.BASE_DIR)
if repo.bare:
logging.debug('Repo is bare')
return

logging.debug(f'Current git commit: {repo.head.commit.hexsha}')

try:
for remote in repo.remotes:
remote.fetch()

if repo.head.is_detached:
logging.debug('Repo is in detached state')
return

current_branch = repo.active_branch
tracking_branch = current_branch.tracking_branch()

if tracking_branch is None:
logging.debug("Current branch does not track a remote branch.")
return
if current_branch.commit.hexsha == tracking_branch.commit.hexsha:
logging.debug('No git branch updates.')
return

logging.debug(f'Git branch updates found: {current_branch.commit.hexsha} -> {tracking_branch.commit.hexsha}')
config.ui.print_warning('MedPerf client updates found. Please, update your MedPerf installation.')
except GitCommandError as e:
logging.debug('Exception raised during updates check. Maybe user checked out repo with git@ and private key'
'or repo is in detached / non-tracked state?')
logging.debug(e)


class spawn_and_kill:
def __init__(self, cmd, timeout=None, *args, **kwargs):
self.cmd = cmd
Expand Down
1 change: 1 addition & 0 deletions cli/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ schema==0.7.5
setuptools<=66.1.1
email-validator==2.0.0
auth0-python==4.3.0
GitPython==3.1.41

0 comments on commit 824c432

Please sign in to comment.