def main_merge(args): bfn = args.base lfn = args.local rfn = args.remote mfn = args.out from nbdime.args import process_diff_flags process_diff_flags(args) for fn in (bfn, lfn, rfn): if not os.path.exists(fn) and fn != EXPLICIT_MISSING_FILE: logger.error("Cannot find file '%s'", fn) return 1 if lfn == rfn == EXPLICIT_MISSING_FILE: # Deleted both locally and remotely # Special case not well solved by routines below _handle_agreed_deletion(bfn, mfn, args) # Agreed on deletion = no conflics = return 0 return 0 formatting = detect(bfn) or detect(lfn) or detect(rfn) b = read_package_json(bfn) l = read_package_json(lfn) r = read_package_json(rfn) merged, decisions = merge(b, l, r, args) conflicted = [d for d in decisions if d.conflict] returncode = 1 if conflicted else 0 if conflicted: logger.warning("Conflicts occured during merge operation.") else: logger.debug( "Merge completed successfully with no unresolvable conflicts.") if args.decisions: # Print merge decisions (including unconflicted) config = prettyprint_config_from_args(args, out=io.StringIO()) pretty_print_merge_decisions(b, decisions, config=config) logger.warning("Decisions:\n%s", config.out.getvalue()) elif mfn: # Write partial or fully completed merge to given foo.ipynb filename with io.open(mfn, "w", encoding="utf8", newline=formatting.newline) as f: json.dump(merged, f, indent=formatting.indent) f.write(formatting.newline) logger.info("Merge result written to %s", mfn) else: # Write merged notebook to terminal json.dump(merged, sys.stdout) return returncode
def main_diff(args): """Main handler of diff CLI""" output = getattr(args, 'out', None) process_diff_flags(args) base, remote, paths = resolve_diff_args(args) # Check if base/remote are gitrefs: if is_gitref(base) and is_gitref(remote): # We are asked to do a diff of git revisions: status = 0 for fbase, fremote in changed_notebooks(base, remote, paths): status = _handle_diff(fbase, fremote, output, args) if status != 0: # Short-circuit on error in diff handling return status return status else: # Not gitrefs: return _handle_diff(base, remote, output, args)