From 97bd5ac045965008f6743e5554f841091883d1ff Mon Sep 17 00:00:00 2001 From: Derek Higgins Date: Thu, 21 Mar 2024 10:24:55 +0000 Subject: [PATCH] generate list: Add commit support (#655) Now supports a diff from a specific commit (in addition to a branch or HEAD) Fixes #654 Signed-off-by: Derek Higgins --- cli/generator/generate_data.py | 18 ++++++++++++++---- tests/test_lab_list.py | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cli/generator/generate_data.py b/cli/generator/generate_data.py index cfa628b03476..cb044b75a16d 100755 --- a/cli/generator/generate_data.py +++ b/cli/generator/generate_data.py @@ -23,6 +23,7 @@ # Third Party from rouge_score import rouge_scorer +import gitdb # import numpy as np import tqdm @@ -467,13 +468,22 @@ def get_taxonomy_diff(repo="taxonomy", base="origin/main"): repo = git.Repo(repo) untracked_files = [u for u in repo.untracked_files if istaxonomyfile(u)] + branches = [b.name for b in repo.branches] + head_commit = None - if base == "HEAD": - head_commit = repo.commit("HEAD") - elif "/" in base: + if "/" in base: re_git_branch = re.compile(f"remotes/{base}$", re.MULTILINE) - else: + elif base in branches: re_git_branch = re.compile(f"{base}$", re.MULTILINE) + else: + try: + head_commit = repo.commit(base) + except gitdb.exc.BadName as exc: + raise SystemExit( + yaml.YAMLError( + f'Couldn\'t find the taxonomy git ref "{base}" from the current HEAD' + ) + ) from exc # Move backwards from HEAD until we find the first commit that is part of base # then we can take our diff from there diff --git a/tests/test_lab_list.py b/tests/test_lab_list.py index ea320a822e83..273256186bed 100644 --- a/tests/test_lab_list.py +++ b/tests/test_lab_list.py @@ -93,7 +93,7 @@ def test_list_invalid_base(self): ) self.assertIsNone(result.exception) self.assertIn( - f'Couldn\'t find the taxonomy base branch "{taxonomy_base}" ' + f'Couldn\'t find the taxonomy git ref "{taxonomy_base}" ' "from the current HEAD", result.output, )