예제 #1
0
def test_install_raises_template_conflict(repo: Repository,
                                          template_repo: Repository):
    # Create an existing template branch to force the error.
    repo.create_branch('template', repo[repo.head.target])

    battenberg = Battenberg(repo)

    with pytest.raises(TemplateConflictException):
        battenberg.install(template_repo.workdir)
예제 #2
0
def install(ctx, template: str, initial_branch: Optional[str], **kwargs):
    """Create a new copy from the TEMPLATE repository.

    TEMPLATE is expected to be the URL of a git repository.
    """

    battenberg = Battenberg(
        open_or_init_repository(ctx.obj['target'], template, initial_branch))
    battenberg.install(template, **kwargs)
예제 #3
0
def test_install_raises_failed_hook(cookiecutter: Mock, repo: Repository,
                                    template_repo: Repository):
    cookiecutter.side_effect = FailedHookException

    battenberg = Battenberg(repo)

    with pytest.raises(SystemExit) as e:
        battenberg.install(template_repo.workdir)

    assert e.value.code == 1
예제 #4
0
def upgrade(ctx, **kwargs):
    try:
        battenberg = Battenberg(open_repository(ctx.obj['target']))
        battenberg.upgrade(**kwargs)
    except MergeConflictException:
        # Just run "git status" in a subprocess so we don't have to re-implement the formatting
        # logic atop pygit2.
        completed_process = subprocess.run(['git', 'status'], stdout=subprocess.PIPE,
                                           stderr=subprocess.STDOUT)
        click.echo(completed_process.stdout.decode('utf-8'))
        click.echo('Cannot merge upgrade automatically, please manually resolve the conflicts')
        sys.exit(1)  # Ensure we exit with a failure code.
예제 #5
0
def test_upgrade_fetches_remote_template(installed_repo: Repository,
                                         template_repo: Repository):
    # installed_repo.remotes.create('origin', '[email protected]:zillow/battenberg.git')
    template_oid = installed_repo.references.get('refs/heads/template').target
    installed_repo.branches.remote.create('origin/template',
                                          installed_repo[template_oid])
    installed_repo.branches.local.delete('template')

    # Couldn't work out a nice way to neatly construct remote branches, resort to mocking.
    with patch.object(installed_repo.references, 'get') as get_mock:
        get_mock.return_value.target = template_oid

        battenberg = Battenberg(installed_repo)
        battenberg.upgrade(checkout='upgrade', no_input=True)

        get_mock.assert_called_once_with('refs/remotes/origin/template')
예제 #6
0
def test_upgrade(installed_repo: Repository, template_repo: Repository):
    battenberg = Battenberg(installed_repo)
    battenberg.upgrade(checkout='upgrade', no_input=True)

    template_oids = {
        ref.oid_new
        for ref in installed_repo.references['refs/heads/template'].log()
    }
    template_commits = [installed_repo[oid].message for oid in template_oids]
    assert not set(template_commits) - {
        'Prepared template installation', 'Prepared template upgrade'
    }

    template_upgrade_message = f'commit (merge): Upgraded template \'{template_repo.workdir}\''
    master_merge_ref = find_ref_from_message(installed_repo,
                                             template_upgrade_message)
    assert master_merge_ref
    # Ensure the merge commit was derived from the template branch.
    assert template_oids & set(
        installed_repo[master_merge_ref.oid_new].parent_ids)
예제 #7
0
def test_update_merge_target(installed_repo: Repository,
                             template_repo: Repository):
    merge_target = 'target'
    battenberg = Battenberg(installed_repo)
    battenberg.upgrade(checkout='upgrade',
                       no_input=True,
                       merge_target=merge_target)

    template_upgrade_oid = next(
        ref.oid_new
        for ref in installed_repo.references['refs/heads/template'].log()
        if installed_repo[ref.oid_new].message == 'Prepared template upgrade')

    template_upgrade_message = f'commit (merge): Upgraded template \'{template_repo.workdir}\''
    master_merge_ref = find_ref_from_message(installed_repo,
                                             template_upgrade_message,
                                             ref_name=merge_target)
    assert master_merge_ref
    # Ensure the merge commit on the merge target branch was derived from the template branch.
    assert template_upgrade_oid in set(
        installed_repo[master_merge_ref.oid_new].parent_ids)
예제 #8
0
def test_install(repo: Repository, template_repo: Repository):
    battenberg = Battenberg(repo)
    battenberg.install(template_repo.workdir, no_input=True)

    assert battenberg.is_installed()
    # Ensure we have the appropriate branches we expect.
    assert not {'master', 'template'} - set(repo.listall_branches())

    # Ensure we have a valid structure for the template branch.
    template_oids = {
        ref.oid_new
        for ref in repo.references['refs/heads/template'].log()
    }
    template_commits = [repo[oid].message for oid in template_oids]
    assert template_commits == ['Prepared template installation']

    # Ensure we have valid merge commit from the template branch -> master.
    template_install_message = f'commit (merge): Installed template \'{template_repo.workdir}\''
    master_merge_ref = find_ref_from_message(repo, template_install_message)
    assert master_merge_ref
    # Ensure the merge commit was derived from the template branch.
    assert not template_oids - set(repo[master_merge_ref.oid_new].parent_ids)
예제 #9
0
파일: cli.py 프로젝트: kevinj-z/battenberg
def install(ctx, template: str, **kwargs):
    battenberg = Battenberg(open_or_init_repository(ctx.obj['target']))
    battenberg.install(template, **kwargs)
예제 #10
0
def test_upgrade_raises_template_not_found(repo: Repository):
    repo.remotes.delete('origin')
    battenberg = Battenberg(repo)
    with pytest.raises(TemplateNotFoundException):
        battenberg.upgrade()
예제 #11
0
def installed_repo(repo: Repository, template_repo: Repository) -> Repository:
    battenberg = Battenberg(repo)
    battenberg.install(template_repo.workdir, no_input=True)
    return repo