check out a specific reference when cloning the repo
When cloning or updating the local copy of the repository, set the working copy to a specific SHA so the validation steps can look at the files on the filesystem. Change-Id: I913b4608eae18c6e85982a5dff3b5388ad80eda6 Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
		@@ -231,7 +231,7 @@ def validate_releases(deliverable_info, zuul_layout,
 | 
			
		||||
                # Ensure we have a local copy of the repository so we
 | 
			
		||||
                # can scan for values that are more difficult to get
 | 
			
		||||
                # remotely.
 | 
			
		||||
                gitutils.clone_repo(workdir, project['repo'])
 | 
			
		||||
                gitutils.clone_repo(workdir, project['repo'], project['hash'])
 | 
			
		||||
 | 
			
		||||
                # Check that the sdist name and tarball-base name match.
 | 
			
		||||
                if link_mode == 'tarball':
 | 
			
		||||
 
 | 
			
		||||
@@ -64,30 +64,36 @@ def tag_exists(repo, ref):
 | 
			
		||||
    return links.link_exists(url)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def clone_repo(workdir, repo):
 | 
			
		||||
def clone_repo(workdir, repo, ref=None):
 | 
			
		||||
    "Check out the code."
 | 
			
		||||
    dest = os.path.join(workdir, repo)
 | 
			
		||||
    if os.path.exists(dest):
 | 
			
		||||
        return
 | 
			
		||||
    cmd = [
 | 
			
		||||
        'zuul-cloner',
 | 
			
		||||
        '--workspace', workdir,
 | 
			
		||||
    ]
 | 
			
		||||
    cache_dir = os.environ.get('ZUUL_CACHE_DIR', '/opt/git')
 | 
			
		||||
    if cache_dir and os.path.exists(cache_dir):
 | 
			
		||||
        cmd.extend(['--cache-dir', cache_dir])
 | 
			
		||||
    cmd.extend([
 | 
			
		||||
        'git://git.openstack.org',
 | 
			
		||||
        repo,
 | 
			
		||||
    ])
 | 
			
		||||
    subprocess.check_call(cmd)
 | 
			
		||||
    # Force an update, just in case the local version is still out of
 | 
			
		||||
    # date.
 | 
			
		||||
    print('Updating newly cloned repository in %s' % dest)
 | 
			
		||||
    subprocess.check_call(
 | 
			
		||||
        ['git', 'fetch', '-v', '--tags'],
 | 
			
		||||
        cwd=dest,
 | 
			
		||||
    )
 | 
			
		||||
    if not os.path.exists(dest):
 | 
			
		||||
        cmd = [
 | 
			
		||||
            'zuul-cloner',
 | 
			
		||||
            '--workspace', workdir,
 | 
			
		||||
        ]
 | 
			
		||||
        cache_dir = os.environ.get('ZUUL_CACHE_DIR', '/opt/git')
 | 
			
		||||
        if cache_dir and os.path.exists(cache_dir):
 | 
			
		||||
            cmd.extend(['--cache-dir', cache_dir])
 | 
			
		||||
        cmd.extend([
 | 
			
		||||
            'git://git.openstack.org',
 | 
			
		||||
            repo,
 | 
			
		||||
        ])
 | 
			
		||||
        subprocess.check_call(cmd)
 | 
			
		||||
        # Force an update, just in case the local version is still out of
 | 
			
		||||
        # date.
 | 
			
		||||
        print('Updating newly cloned repository in %s' % dest)
 | 
			
		||||
        subprocess.check_call(
 | 
			
		||||
            ['git', 'fetch', '-v', '--tags'],
 | 
			
		||||
            cwd=dest,
 | 
			
		||||
        )
 | 
			
		||||
    # If we were given some sort of reference, check that out.
 | 
			
		||||
    if ref:
 | 
			
		||||
        print('Updating %s to %s' % (repo, ref))
 | 
			
		||||
        subprocess.check_call(
 | 
			
		||||
            ['git', 'checkout', ref],
 | 
			
		||||
            cwd=dest,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def sha_for_tag(workdir, repo, version):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user