Currently, kas doesn't validate if a lockfile commit is valid when
calling 'kas lock --update'. This command would just replace it with a
new valid commit, but generating the diff between the two commits always
raises an uncaught error. This change logs the problem and then proceeds
with the replacement as intended.
Signed-off-by: Tamino Larisch <
tamino....@siemens.com>
---
kas/plugins/lock.py | 5 ++++-
kas/repos.py | 10 +++++++---
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/kas/plugins/lock.py b/kas/plugins/lock.py
index d244e87..e7a87de 100644
--- a/kas/plugins/lock.py
+++ b/kas/plugins/lock.py
@@ -81,7 +81,7 @@ from kas.includehandler import ConfigFile
from kas.plugins.checkout import Checkout
from kas.plugins.dump import Dump, IoTarget, LOCKFILE_VERSION_MIN
from kas.plugins.diff import Diff
-from kas.repos import Repo
+from kas.repos import Repo, RepoRefError
__license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2024'
@@ -112,6 +112,9 @@ class Lock(Checkout):
diff = repo.diff(old_commit, None)
except NotImplementedError:
return
+ except RepoRefError as e:
+ logging.warning(e)
+ return
Diff.formatting_diff_output(
None, None, {'vcs': diff}, True, False, True, False)
diff --git a/kas/repos.py b/kas/repos.py
index 9664d85..3bec725 100644
--- a/kas/repos.py
+++ b/kas/repos.py
@@ -39,7 +39,7 @@ from .context import get_context
from .libkas import run_cmd_async, run_cmd
from .kasusererror import KasUserError
from functools import cached_property
-from git import Repo as GitPythonRepo
+from git import GitCommandError, Repo as GitPythonRepo
__license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2017-2018'
@@ -805,8 +805,12 @@ class GitRepo(RepoImpl):
shallow_file = os.path.join(git_repo.git_dir, 'shallow')
if os.path.isfile(shallow_file):
git_repo.git.fetch(unshallow=True)
- commits = list(git_repo.iter_commits(
- f'{commit1}..{commit2}'))
+ try:
+ commits = list(git_repo.iter_commits(
+ f'{commit1}..{commit2}'))
+ except GitCommandError as e:
+ raise RepoRefError(f'Could not compute diff for commits "{commit1}"..'
+ f'"{commit2}" in repository "{
self.name}": {e}')
diff_json = {
self.name: []}
for commit in commits:
diff_json[
self.name].append({
--
2.39.5