]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
For clones, look for error regardless of exit code
authorZack Cerza <zack.cerza@inktank.com>
Wed, 27 Aug 2014 17:25:30 +0000 (11:25 -0600)
committerZack Cerza <zack.cerza@inktank.com>
Wed, 27 Aug 2014 17:25:30 +0000 (11:25 -0600)
This fixes a bug on older git versions, where it would happily cloen a
repo and give you the wrong branch if the one you requested did not
exist.

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

index 20027404e3f0507dd4f2dd1a7130ef8a7f155651..bc3d434bac74afa22f9ad7d30eb151f311a02aef 100644 (file)
@@ -62,14 +62,21 @@ def clone_repo(repo_url, dest_path, branch):
         cwd=os.path.dirname(dest_path),
         stdout=subprocess.PIPE,
         stderr=subprocess.STDOUT)
-    if proc.wait() != 0:
-        not_found_str = "Remote branch %s not found" % branch
-        out = proc.stdout.read()
+
+    not_found_str = "Remote branch %s not found" % branch
+    out = proc.stdout.read()
+    result = proc.wait()
+    # Newer git versions will bail if the branch is not found, but older ones
+    # will not. Fortunately they both output similar text.
+    if not_found_str in out:
         log.error(out)
-        if not_found_str in out:
-            raise BranchNotFoundError(branch, repo_url)
-        else:
-            raise GitError("git clone failed!")
+        if result == 0:
+            # Old git left a repo with the wrong branch. Remove it.
+            shutil.rmtree(dest_path, ignore_errors=True)
+        raise BranchNotFoundError(branch, repo_url)
+    elif result != 0:
+        # Unknown error
+        raise GitError("git clone failed!")
 
 
 def fetch(repo_path):