Skip to content

Commit

Permalink
For clones, look for error regardless of exit code
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Zack Cerza committed Aug 27, 2014
1 parent 4d44c82 commit 95a08b5
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions teuthology/repo_utils.py
Expand Up @@ -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):
Expand Down

0 comments on commit 95a08b5

Please sign in to comment.