diff mbox series

[meta,3/3] oeqa/utils/metadata: Handle empty git repos in git_rev_info

Message ID 20260707211507.2585072-3-john.ripple@keysight.com
State New
Headers show
Series Create selftest suite for go-vendor.bbclass | expand

Commit Message

John Ripple July 7, 2026, 9:14 p.m. UTC
git_rev_info() calls repo.head.commit without guarding against
ValueError, which gitpython raises when HEAD points to an unborn
branch (e.g. a freshly-initialised layer directory with no commits).
Wrap the commit-info block in try/except so metadata collection
continues rather than crashing with a non-zero exit code.

Signed-off-by: John Ripple <john.ripple@keysight.com>
---
 meta/lib/oeqa/utils/metadata.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/utils/metadata.py b/meta/lib/oeqa/utils/metadata.py
index b320df67e0..c8df17392d 100644
--- a/meta/lib/oeqa/utils/metadata.py
+++ b/meta/lib/oeqa/utils/metadata.py
@@ -85,12 +85,15 @@  def git_rev_info(path):
         repo = Repo(path, search_parent_directories=True)
     except (InvalidGitRepositoryError, NoSuchPathError):
         return info
-    info['commit'] = repo.head.commit.hexsha
-    info['commit_count'] = repo.head.commit.count()
-    info['commit_time'] = repo.head.commit.committed_date
+    try:
+        info['commit'] = repo.head.commit.hexsha
+        info['commit_count'] = repo.head.commit.count()
+        info['commit_time'] = repo.head.commit.committed_date
+    except (ValueError, TypeError):
+        pass
     try:
         info['branch'] = repo.active_branch.name
-    except TypeError:
+    except (TypeError, ValueError):
         info['branch'] = '(nobranch)'
     return info