Improve missing branch detection and logging

Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
This commit is contained in:
Zack Cerza 2014-06-26 13:37:24 -06:00
parent abd359086c
commit f5bed55d47

View File

@ -17,21 +17,29 @@ def checkout_repo(repo_url, dest_path, branch):
if not os.path.isdir(dest_path):
log.info("Cloning %s %s from upstream", repo_url, branch)
log.info(
subprocess.check_output(('git', 'clone', '--branch', branch,
repo_url, dest_path),
cwd=os.path.dirname(dest_path))
)
proc = subprocess.Popen(
('git', 'clone', '--branch', branch, repo_url, dest_path),
cwd=os.path.dirname(dest_path),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
not_found_str = "Remote branch %s not found" % branch
out = proc.stdout.read()
if proc.wait() != 0:
log.error(out)
if not_found_str in out:
raise BranchNotFoundError(branch, repo_url)
else:
raise RuntimeError("git clone failed!")
elif time.time() - os.stat('/etc/passwd').st_mtime > 60:
# only do this at most once per minute
log.info("Fetching %s from upstream", branch)
log.info(
subprocess.check_output(('git', 'fetch', '-p', 'origin'),
cwd=dest_path)
)
log.info(
subprocess.check_output(('touch', dest_path))
)
out = subprocess.check_output(('git', 'fetch', '-p', 'origin'),
cwd=dest_path)
if out:
log.info(out)
out = subprocess.check_output(('touch', dest_path))
if out:
log.info(out)
else:
log.info("%s was just updated; assuming it is current", branch)