From: Zack Cerza Date: Wed, 19 Oct 2016 20:55:05 +0000 (-0600) Subject: Add repo_utils.ls_remote() X-Git-Tag: 1.1.0~512^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8ff8e27d819624f149995eca6c496fd18b94ae82;p=teuthology.git Add repo_utils.ls_remote() ... by moving most of suite.util.git_ls_remote's code to that module. Signed-off-by: Zack Cerza --- diff --git a/teuthology/repo_utils.py b/teuthology/repo_utils.py index c57308eb3b..a815f35549 100644 --- a/teuthology/repo_utils.py +++ b/teuthology/repo_utils.py @@ -36,6 +36,20 @@ def is_fresh(path): return False +def ls_remote(url, ref): + """ + Return the current sha1 for a given repository and ref + + :returns: The sha1 if found; else None + """ + cmd = "git ls-remote {} {}".format(url, ref) + result = subprocess.check_output( + cmd, shell=True).split() + sha1 = result[0] if result else None + log.debug("{} -> {}".format(cmd, sha1)) + return sha1 + + def enforce_repo_state(repo_url, dest_path, branch, remove_on_error=True): """ Use git to either clone or update a given repo, forcing it to switch to the diff --git a/teuthology/suite/util.py b/teuthology/suite/util.py index 4f7cf99df9..7dd78c010b 100644 --- a/teuthology/suite/util.py +++ b/teuthology/suite/util.py @@ -11,6 +11,7 @@ import sys from email.mime.text import MIMEText from .. import lock +from .. import repo_utils from ..config import config from ..exceptions import BranchNotFoundError, ScheduleFailError @@ -175,12 +176,7 @@ def git_ls_remote(project, branch, project_owner='ceph'): :returns: The sha1 if found; else None """ url = build_git_url(project, project_owner) - cmd = "git ls-remote {} {}".format(url, branch) - result = subprocess.check_output( - cmd, shell=True).split() - sha1 = result[0] if result else None - log.debug("{} -> {}".format(cmd, sha1)) - return sha1 + return repo_utils.ls_remote(url, branch) def git_validate_sha1(project, sha1, project_owner='ceph'):