Ejemplo n.º 1
0
def handle_agreed_deletion(base_fn, output_fn, print_decisions=False):
    """Handle merge when file has been deleted both locally and remotely"""
    assert base_fn != EXPLICIT_MISSING_FILE, (
        'sanity check failed: cannot have agreed decision on base %r' % base_fn)
    b = read_notebook(base_fn, on_null='minimal')
    if print_decisions:
        # Print merge decision (delete all)
        from nbdime.diffing.notebooks import diff_notebooks
        from nbdime.merging.decisions import MergeDecisionBuilder
        # Build diff for deleting all content:
        diff = diff_notebooks(b, {})
        # Make agreed decision from diff:
        bld = MergeDecisionBuilder()
        bld.agreement([], local_diff=diff, remote_diff=diff)
        decisions = bld.validated(b)
        # Print decition
        config = PrettyPrintConfig(out=io.StringIO())
        pretty_print_merge_decisions(b, decisions, config=config)
        nbdime.log.warning("Decisions:\n%s", out.getvalue())

    elif output_fn:
        # Delete file if existing, if not do nothing
        if os.path.exists(output_fn):
            os.remove(output_fn)
            nbdime.log.info("Output file deleted: %s", output_fn)
Ejemplo n.º 2
0
def test_merge_builder_ensures_common_path():
    b = MergeDecisionBuilder()
    b.conflict(("a", "b"),
               [op_patch("c", [op_remove("d")])],
               [op_patch("c", [op_remove("e")])])
    assert len(b.decisions) == 1
    assert b.decisions[0].common_path == ("a", "b", "c")
    assert b.decisions[0].local_diff == [op_remove("d")]
    assert b.decisions[0].remote_diff == [op_remove("e")]
Ejemplo n.º 3
0
def test_build_diffs_sorted():
    b = MergeDecisionBuilder()
    b.onesided((), [op_remove('a')], None)
    b.onesided(('b', ), [op_remove('j')], None)
    b.onesided(('c', ), [op_remove('k')], None)
    b.onesided(('d', ), [op_remove('l')], None)
    base = dict(a=1, b=dict(i=2), c=dict(j=3), d=dict(k=4))
    decisions = b.validated(base)
    diff = build_diffs(base, decisions, 'local')
    assert len(diff) == 4
    assert diff[0] == op_patch('d', [op_remove('l')])
    assert diff[1] == op_patch('c', [op_remove('k')])
    assert diff[2] == op_patch('b', [op_remove('j')])
    assert diff[3] == op_remove('a')
Ejemplo n.º 4
0
def test_build_diffs_sorted():
    b = MergeDecisionBuilder()
    b.onesided((), [op_remove('a')], None)
    b.onesided(('b',), [op_remove('j')], None)
    b.onesided(('c',), [op_remove('k')], None)
    b.onesided(('d',), [op_remove('l')], None)
    base = dict(a=1, b=dict(i=2), c=dict(j=3), d=dict(k=4))
    decisions = b.validated(base)
    diff = build_diffs(base, decisions, 'local')
    assert len(diff) == 4
    assert diff[0] == op_patch('d', [op_remove('l')])
    assert diff[1] == op_patch('c', [op_remove('k')])
    assert diff[2] == op_patch('b', [op_remove('j')])
    assert diff[3] == op_remove('a')
Ejemplo n.º 5
0
def handle_agreed_deletion(base_fn, output_fn, print_decisions=False):
    """Handle merge when file has been deleted both locally and remotely"""
    assert base_fn != EXPLICIT_MISSING_FILE
    b = read_notebook(base_fn, on_null='minimal')
    if print_decisions:
        # Print merge decision (delete all)
        from nbdime.diffing.notebooks import diff_notebooks
        from nbdime.merging.decisions import MergeDecisionBuilder
        # Build diff for deleting all content:
        diff = diff_notebooks(b, {})
        # Make agreed decision from diff:
        bld = MergeDecisionBuilder()
        bld.agreement([], local_diff=diff, remote_diff=diff)
        decisions = bld.validated(b)
        # Print decition
        out = io.StringIO()
        pretty_print_merge_decisions(b, decisions, out=out)
        nbdime.log.warning("Decisions:\n%s", out.getvalue())

    elif output_fn:
        # Delete file if existing, if not do nothing
        if os.path.exists(output_fn):
            os.remove(output_fn)
            nbdime.log.info("Output file deleted: %s", output_fn)