]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
repo_utils: Call git set remote-url 807/head
authorZack Cerza <zack@redhat.com>
Fri, 4 Mar 2016 16:23:31 +0000 (09:23 -0700)
committerZack Cerza <zack@redhat.com>
Fri, 4 Mar 2016 16:23:31 +0000 (09:23 -0700)
This will cause git repos on-disk to be updated to point at the correct
remote based on config.ceph_git_base_url

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/repo_utils.py

index fe228a99517d0dab13342c06d5b85dff44dbdd9f..3c9b0085f55349d9aef373da3d72a6cdd8cbd060 100644 (file)
@@ -30,6 +30,7 @@ def enforce_repo_state(repo_url, dest_path, branch, remove_on_error=True):
             clone_repo(repo_url, dest_path, branch)
         elif time.time() - os.stat('/etc/passwd').st_mtime > 60:
             # only do this at most once per minute
+            set_remote(dest_path, repo_url)
             fetch(dest_path)
             out = subprocess.check_output(('touch', dest_path))
             if out:
@@ -79,6 +80,26 @@ def clone_repo(repo_url, dest_path, branch):
         raise GitError("git clone failed!")
 
 
+def set_remote(repo_path, repo_url):
+    """
+    Call "git remote set-url origin <repo_url>"
+
+    :param repo_url:  The full URL to the repo (not including the branch)
+    :param repo_path: The full path to the repository
+    :raises:          GitError if the operation fails
+    """
+    log.debug("Setting repo remote to  %s", repo_url)
+    proc = subprocess.Popen(
+        ('git', 'remote', 'set-url', 'origin', repo_url),
+        cwd=repo_path,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.STDOUT)
+    if proc.wait() != 0:
+        out = proc.stdout.read()
+        log.error(out)
+        raise GitError("git remote set-url failed!")
+
+
 def fetch(repo_path):
     """
     Call "git fetch -p origin"