Fix updating issue when given remote url diffs origin
authorLingchaox Xin <lingchaox.xin@intel.com>
Mon, 16 Sep 2013 09:29:11 +0000 (17:29 +0800)
committerEduard Bartosh <eduard.bartosh@intel.com>
Mon, 16 Sep 2013 10:26:34 +0000 (03:26 -0700)
Change-Id: Ied117af83bb4d654d03efee856f1276bbcb85f1c
Reviewed-on: https://otctools.jf.intel.com/review/6465
Tested-by: OTC Tools Tester <ed.bartosh@linux.intel.com>
Reviewed-by: Eduard Bartosh <eduard.bartosh@intel.com>
common/git.py

index 32e618c..fe99db7 100644 (file)
@@ -88,7 +88,10 @@ def _update_gitproject(localdir, gitpath=None):
         localgit = Git(localdir)
         if not localgit.bare:
             localgit.pull(repo=gitpath, all_repos=True)
-        localgit.fetch(repo=gitpath)
+        if gitpath and localgit.get_remote_repos().get('origin')[0] != gitpath:
+            os.system('git --git-dir=%s remote set-url origin %s' % ([localdir,
+                os.path.join(localdir, '.git')][localgit.bare], gitpath))
+        localgit.fetch(all_remotes=True)
     except GitRepositoryError, gre:
         print('git execption: ', gre)
         shutil.rmtree(localdir)