[PATCH] Check the validity of git repository.

Abhinav Jain jainab.2009 at gmail.com
Mon Mar 26 04:36:05 UTC 2018


Please check if this works. 

Thanks and Regards
Abhinav Jain

Earlier the function valid was checking the validity of the git repository,
the program was working in. For doing this the function was first checking
whether path exists or not and after that it was checking whether the
directory is a git repository or not and to do so, it
was relying on git status. Since the git status looks for the .git file in
the current directory and if not found it will look up in the tree and if finds
a .git file there it will return valid, which voids the purpose of use.
Now to solve this problem, a function _valid_repo_path is created to check
for the .git file and every function which looks for the validity of
git repository will call this function to check. Closes #2522
 source-builder/sb/git.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/source-builder/sb/git.py b/source-builder/sb/git.py
index be23396..0d139f9 100644
--- a/source-builder/sb/git.py
+++ b/source-builder/sb/git.py
@@ -38,9 +38,12 @@ class repo:
         if ec:
             raise error.general('git command failed (%s): %d' % (self.git, ec))
+    def _valid_repo_path(self):
+    	return path.exists(path.join(self.path, '.git'))
     def _run(self, args, check = False):
         e = execute.capture_execution()
-        if path.exists(self.path):
+        if _valid_repo_path():
             cwd = self.path
             cwd = None
@@ -122,7 +125,7 @@ class repo:
     def status(self, submodules_always_clean = False):
         _status = {}
-        if path.exists(self.path):
+        if _valid_repo_path():
             if submodules_always_clean:
                 submodules = self.submodules()
@@ -166,7 +169,7 @@ class repo:
         return not (len(_status) == 1 and 'branch' in _status)
     def valid(self):
-        if path.exists(self.path):
+        if _valid_repo_path():
             ec, output = self._run(['status'])
             return ec == 0
         return False
@@ -233,4 +236,4 @@ if __name__ == '__main__':
     print('g.dirty():', g.dirty())
     print('g.remotes():', g.remotes())
     print('g.email():', g.email())
     print('g.head():', g.head())
\ No newline at end of file

More information about the devel mailing list