示例#1
0
def test_clone(store, tmpdir_factory, log_info_mock):
    path = git_dir(tmpdir_factory)
    with local.cwd(path):
        local['git']('commit', '--allow-empty', '-m', 'foo')
        sha = get_head_sha(path)
        local['git']('commit', '--allow-empty', '-m', 'bar')

    ret = store.clone(path, sha)
    # Should have printed some stuff
    log_info_mock.assert_called_with('This may take a few minutes...')

    # Should return a directory inside of the store
    assert os.path.exists(ret)
    assert ret.startswith(store.directory)
    # Directory should start with `repo`
    _, dirname = os.path.split(ret)
    assert dirname.startswith('repo')
    # Should be checked out to the sha we specified
    assert get_head_sha(ret) == sha

    # Assert that we made a symlink from the sha to the repo
    sha_path = os.path.join(store.directory, sha + '_' + hex_md5(path))
    assert os.path.exists(sha_path)
    assert os.path.islink(sha_path)
    assert os.readlink(sha_path) == ret
示例#2
0
def test_clone(store, tmpdir_factory, log_info_mock):
    path = git_dir(tmpdir_factory)
    with cwd(path):
        cmd_output('git', 'commit', '--allow-empty', '-m', 'foo')
        sha = get_head_sha(path)
        cmd_output('git', 'commit', '--allow-empty', '-m', 'bar')

    ret = store.clone(path, sha)
    # Should have printed some stuff
    log_info_mock.assert_called_with('This may take a few minutes...')

    # Should return a directory inside of the store
    assert os.path.exists(ret)
    assert ret.startswith(store.directory)
    # Directory should start with `repo`
    _, dirname = os.path.split(ret)
    assert dirname.startswith('repo')
    # Should be checked out to the sha we specified
    assert get_head_sha(ret) == sha

    # Assert that we made a symlink from the sha to the repo
    sha_path = os.path.join(store.directory, sha + '_' + hex_md5(path))
    assert os.path.exists(sha_path)
    assert os.path.islink(sha_path)
    assert os.readlink(sha_path) == ret
示例#3
0
def test_clone_when_repo_already_exists(store):
    # Create a symlink and directory in the store simulating an already
    # created repository.
    store.require_created()
    repo_dir_path = os.path.join(store.directory, 'repo_dir')
    os.mkdir(repo_dir_path)
    os.symlink(
        repo_dir_path,
        os.path.join(store.directory, 'fake_sha' + '_' + hex_md5('url')),
    )

    ret = store.clone('url', 'fake_sha')
    assert ret == repo_dir_path
示例#4
0
def test_clone_when_repo_already_exists(store):
    # Create a symlink and directory in the store simulating an already
    # created repository.
    store.require_created()
    repo_dir_path = os.path.join(store.directory, 'repo_dir')
    os.mkdir(repo_dir_path)
    os.symlink(
        repo_dir_path,
        os.path.join(store.directory, 'fake_sha' + '_' + hex_md5('url')),
    )

    ret = store.clone('url', 'fake_sha')
    assert ret == repo_dir_path
示例#5
0
    def clone(self, url, sha):
        """Clone the given url and checkout the specific sha."""
        self.require_created()

        # Check if we already exist
        sha_path = os.path.join(self.directory, sha + '_' + hex_md5(url))
        if os.path.exists(sha_path):
            return os.readlink(sha_path)

        logger.info('Installing environment for {0}.'.format(url))
        logger.info('Once installed this environment will be reused.')
        logger.info('This may take a few minutes...')

        dir = tempfile.mkdtemp(prefix='repo', dir=self.directory)
        with clean_path_on_failure(dir):
            local['git']('clone', '--no-checkout', url, dir)
            with local.cwd(dir):
                local['git']('checkout', sha)

        # Make a symlink from sha->repo
        os.symlink(dir, sha_path)
        return dir
示例#6
0
    def clone(self, url, sha):
        """Clone the given url and checkout the specific sha."""
        self.require_created()

        # Check if we already exist
        sha_path = os.path.join(self.directory, sha + '_' + hex_md5(url))
        if os.path.exists(sha_path):
            return os.readlink(sha_path)

        logger.info('Installing environment for {0}.'.format(url))
        logger.info('Once installed this environment will be reused.')
        logger.info('This may take a few minutes...')

        dir = tempfile.mkdtemp(prefix='repo', dir=self.directory)
        with clean_path_on_failure(dir):
            cmd_output('git', 'clone', '--no-checkout', url, dir)
            with cwd(dir):
                cmd_output('git', 'checkout', sha)

        # Make a symlink from sha->repo
        os.symlink(dir, sha_path)
        return dir