]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa/utils/metadata: Allow to function without the git module
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 29 Oct 2018 13:46:52 +0000 (13:46 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 29 Oct 2018 17:01:34 +0000 (17:01 +0000)
The python git module may or may not be enabled, allow this code to
function without it, falling back to the same method as metadata_scm.bbclass
uses. This will be cleaned up in the next round of feature development.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/utils/metadata.py

index 65bbdc61f41507e84b03e079f8bd6d5177267281..b7def77224062a2475556b1ab727fe647d9117ea 100644 (file)
@@ -58,9 +58,22 @@ def metadata_from_data_store(d):
 
 def git_rev_info(path):
     """Get git revision information as a dict"""
-    from git import Repo, InvalidGitRepositoryError, NoSuchPathError
-
     info = OrderedDict()
+
+    try:
+        from git import Repo, InvalidGitRepositoryError, NoSuchPathError
+    except ImportError:
+        import subprocess
+        try:
+            info['branch'] = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=path).decode('utf-8').strip()
+        except subprocess.CalledProcessError:
+            pass
+        try:
+            info['commit'] = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=path).decode('utf-8').strip()
+        except subprocess.CalledProcessError:
+            pass
+        return info
+
     try:
         repo = Repo(path, search_parent_directories=True)
     except (InvalidGitRepositoryError, NoSuchPathError):