]> code.ossystems Code Review - openembedded-core.git/commitdiff
oeqa.utils.git.GitRepo: new arg to require topdir
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Mon, 15 Aug 2016 10:56:58 +0000 (13:56 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 25 Aug 2016 21:59:56 +0000 (22:59 +0100)
Add a new 'is_topdir' argument to the GitRepo init method which
validates that the given path is the top directory of a Git repository.
Without this argument GitRepo also accepts subdirectories of a Git
repository (in which case GitRepo will point to the parent directory
that is the top directory of this repository) which may have undesired
in some cases.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/lib/oeqa/utils/git.py

index 0fc8112321e956c021a2d4d9c88acc699db8e583..ca84680118c20b9aed8f7434ae3ca7e1d3cb15ff 100644 (file)
@@ -4,6 +4,8 @@
 # Released under the MIT license (see COPYING.MIT)
 #
 """Git repository interactions"""
+import os
+
 from oeqa.utils.commands import runCmd
 
 
@@ -13,9 +15,12 @@ class GitError(Exception):
 
 class GitRepo(object):
     """Class representing a Git repository clone"""
-    def __init__(self, cwd):
+    def __init__(self, path, is_topdir=False):
         self.top_dir = self._run_git_cmd_at(['rev-parse', '--show-toplevel'],
-                                            cwd)
+                                            path)
+        realpath = os.path.realpath(path)
+        if is_topdir and realpath != self.top_dir:
+            raise GitError("{} is not a Git top directory".format(realpath))
 
     @staticmethod
     def _run_git_cmd_at(git_args, cwd, **kwargs):