Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --compatible diff flag to output a diff more compatible with other tools #647

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions nbdime/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ def add_prettyprint_args(parser):
default=True,
help=("prevent use of diff/diff3 for formatting diff/merge text output")
)
parser.add_argument(
'--compatible',
dest='compatible',
action="store_true",
default=False,
help=("output a diff compatible with other tools")
)


def prettyprint_config_from_args(arguments, **kwargs):
Expand All @@ -520,6 +527,7 @@ def prettyprint_config_from_args(arguments, **kwargs):
use_color=getattr(arguments, 'use_color', True),
use_git=getattr(arguments, 'use_git', True),
use_diff=getattr(arguments, 'use_diff', True),
compatible=getattr(arguments, 'compatible', False),
**kwargs
)

Expand Down
9 changes: 7 additions & 2 deletions nbdime/prettyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def __init__(
use_git = True,
use_diff = True,
use_color = True,
language = None
language = None,
compatible = False,
):
self.out = out
if include is None:
Expand All @@ -96,6 +97,7 @@ def __init__(
self.use_diff = use_diff
self.use_color = use_color
self.language = language
self.compatible = compatible

def should_ignore_path(self, path):
starred = star_path(split_path(path))
Expand Down Expand Up @@ -824,7 +826,10 @@ def pretty_print_string_diff(a, di, path, config=DefaultConfig):
ta = _trim_base64(a)
tb = _trim_base64(b)

if ta != a or tb != b:
if config.compatible:
diff = diff_render(a if a == ta else ta, b if b == tb else tb, config)
config.out.write(diff)
elif ta != a or tb != b:
if ta != a:
config.out.write('%s%s\n' % (config.REMOVE, ta))
else:
Expand Down