Beispiel #1
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.
Beispiel #2
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')
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
0
def test_upgrade_raises_template_not_found(repo: Repository):
    repo.remotes.delete('origin')
    battenberg = Battenberg(repo)
    with pytest.raises(TemplateNotFoundException):
        battenberg.upgrade()