Fix `Can't update bare repository` bug
authorLingchaox Xin <lingchaox.xin@intel.com>
Mon, 26 Aug 2013 05:07:59 +0000 (13:07 +0800)
committerEduard Bartosh <eduard.bartosh@intel.com>
Wed, 28 Aug 2013 08:07:23 +0000 (01:07 -0700)
Change-Id: I4a4b2bacf16c635e5724b1939db32de831727fe7
Reviewed-on: https://otctools.jf.intel.com/review/6113
Tested-by: OTC Tools Tester <ed.bartosh@linux.intel.com>
Reviewed-by: Eduard Bartosh <eduard.bartosh@intel.com>
common/git.py

index 207dd30..0499d8e 100644 (file)
@@ -80,6 +80,14 @@ class Git(GitRepository):
         else:
             return None
 
+    def ls_remote (self, repo=None):
+        """Displays references available in a remote repository along with the
+        associated commit IDs."""
+        outs, ret = self._git_getoutput('ls-remote', [repo or 'origin'])
+        if not ret:
+            return [out[out.find('refs'):-1] for out in outs if out]
+        return None
+
 def _update_gitproject(localdir, gitpath=None):
     """Fetch latest code to local dir"""
 
@@ -88,7 +96,9 @@ def _update_gitproject(localdir, gitpath=None):
         localgit = Git(localdir)
         if not localgit.bare:
             localgit.pull(repo=gitpath, all_repos=True)
-        localgit.fetch(repo=gitpath, tags=True, all_remotes=True)
+        refs = localgit.ls_remote(repo=gitpath)
+        for ref in refs:
+            localgit.fetch(repo=gitpath, refspec='%s:%s'%(ref, ref))
     except GitRepositoryError, gre:
         print('git execption: ', gre)
         shutil.rmtree(localdir)