diff --git a/contrib/simplemerge b/contrib/simplemerge --- a/contrib/simplemerge +++ b/contrib/simplemerge @@ -106,11 +106,16 @@ except error.Abort: sys.exit(1) - sys.exit( - simplemerge.simplemerge( - ui, local_input, base_input, other_input, **opts - ) + merged_text, conflicts = simplemerge.simplemerge( + ui, local_input, base_input, other_input, **opts ) + if merged_text is not None: + if opts['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 @@ -434,12 +434,18 @@ base.verifytext(ui, quiet=True) other.verifytext(ui, quiet=True) except error.Abort: - r = True + return 1 else: - r = simplemerge.simplemerge(ui, local, base, other, mode=mode) - if not r: - ui.debug(b" premerge successful\n") - return 0 + merged_text, conflicts = simplemerge.simplemerge( + ui, local, base, other, mode=mode + ) + # fcd.flags() already has the merged flags (done in + # mergestate.resolve()) + if merged_text is not None: + local.fctx.write(merged_text, local.fctx.flags()) + if not conflicts: + ui.debug(b" premerge successful\n") + return 0 if premerge not in validkeep: # restore from backup and try again _restorebackup(local.fctx, backup) @@ -480,10 +486,16 @@ base.verifytext(ui) other.verifytext(ui) except error.Abort: - r = True + conflicts = True else: - r = simplemerge.simplemerge(ui, local, base, other, mode=mode) - return True, r, False + merged_text, conflicts = simplemerge.simplemerge( + ui, local, base, other, mode=mode + ) + # fcd.flags() already has the merged flags (done in + # mergestate.resolve()) + if merged_text is not None: + 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 @@ -522,11 +522,4 @@ lines, conflicts = render_minimized(m3, *labels) mergedtext = b''.join(lines) - if opts.get('print'): - 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