diff --git a/contrib/simplemerge b/contrib/simplemerge --- a/contrib/simplemerge +++ b/contrib/simplemerge @@ -116,18 +116,22 @@ _verifytext(base_input, ui, quiet=quiet, allow_binary=allow_binary) _verifytext(other_input, ui, quiet=quiet, allow_binary=allow_binary) - sys.exit( - simplemerge.simplemerge( - ui, - local_input, - base_input, - other_input, - mode, - quiet=True, - allow_binary=allow_binary, - print_result=opts.get(b'print'), - ) + merged_text, conflicts = simplemerge.simplemerge( + ui, + local_input, + base_input, + other_input, + mode, + quiet=True, + allow_binary=allow_binary, + print_result=opts.get(b'print'), ) + if opts.get(b'print'): + ui.fout.write(merged_text) + else: + with open(local, 'wb') as f: + f.write(merged_text) + sys.exit(1 if conflicts else 0) except ParseError as e: e = stringutil.forcebytestr(e) procutil.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e)) diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -442,10 +442,13 @@ stringutil.binary(input.text()) for input in (local, base, other) ): return 1 # continue merging - r = simplemerge.simplemerge( - ui, local, base, other, quiet=True, mode=mode + merged_text, conflicts = simplemerge.simplemerge( + ui, local, base, other, mode=mode ) - if not r: + # fcd.flags() already has the merged flags (done in + # mergestate.resolve()) + local.fctx.write(merged_text, local.fctx.flags()) + if not conflicts: ui.debug(b" premerge successful\n") return 0 if premerge not in validkeep: @@ -489,8 +492,14 @@ _verifytext(other, ui) except error.Abort: return True, True, False - r = simplemerge.simplemerge(ui, local, base, other, mode=mode) - return True, r, False + else: + merged_text, conflicts = simplemerge.simplemerge( + ui, local, base, other, mode=mode + ) + # fcd.flags() already has the merged flags (done in + # mergestate.resolve()) + local.fctx.write(merged_text, local.fctx.flags()) + return True, conflicts, False @internaltool( diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py --- a/mercurial/simplemerge.py +++ b/mercurial/simplemerge.py @@ -532,11 +532,4 @@ lines, conflicts = render_minimized(m3, *labels) mergedtext = b''.join(lines) - if print_result: - ui.fout.write(mergedtext) - else: - # local.fctx.flags() already has the merged flags (done in - # mergestate.resolve()) - local.fctx.write(mergedtext, local.fctx.flags()) - - return conflicts + return mergedtext, conflicts