Turn off file content merge on pull/merge
Andrew Bennetts
andrew.bennetts at canonical.com
Fri Mar 26 00:26:10 GMT 2010
Michael Baytalsky wrote:
>
> Using bazaar 2.1.0 on windows.
>
> Is it possible to completely disable any content merging by bazaar?
>
> I'd very much prefer if it would require me to merge manually if ANY
> conflict in the content occurs. We had some problems recently with
> it merging automatically two corrected files resulting in loosing
> my local tested copy of work - because instead of reporting a
> conflict it merged in somebody's else changes, which partly
> duplicated my work.
>
> There's no way to tell it NOT to merge contents of text files during
> pull and this is sort of scary, because it require to check manually
> the content of all pulled files which were automatically merged.
>
> Also, I've seen a couple of articles recently on how 3-way merging
> can be harmful. So... would be nice to be able to turn it off completely.
Not builtin, but here's a plugin that should turn it off:
---- conservative_merge.py ----
"""Always conflict if both branches have changed a file (avoiding 3-way merge,
etc).
Requires Bazaar 2.1.0 or newer.
"""
from bzrlib.merge import AbstractPerFileMerger, Merger
def conservative_merge_hook(merger):
"""Hook to disable 3-way merge."""
return AlwaysConflictMerger(merger)
class AlwaysConflictMerger(AbstractPerFileMerger):
def __init__(self, merger):
AbstractPerFileMerger.__init__(self, merger)
self._enabled = None
def merge_contents(self, params):
"""Merge the contents of a single file."""
# First, should this custom merge logic be used?
if not self.conservative_enabled():
# Not enabled for this branch
return 'not_applicable', None
elif params.winner == 'other':
# Only changed in OTHER branch, default behaviour is fine.
return 'not_applicable', None
elif not params.is_file_merge():
# THIS and OTHER aren't both files
return 'not_applicable', None
return 'conflicted', params.this_lines
def conservative_enabled(self):
if self._enabled is None:
config = self.merger.this_branch.get_config()
option = config.get_user_option_as_bool('conservative_merge')
if option is None:
# Default to false
option = False
self._enabled = option
return self._enabled
Merger.hooks.install_named_hook(
'merge_file_content', conservative_merge_hook, 'conservative file merge')
---- END ----
To use that,
1) Put that file in your plugins directory (see e.g.
<http://doc.bazaar.canonical.com/plugins/en/plugin-installation.html#per-user-installation>)
2) set "conservative_merge = true" in your configuration somewhere, e.g. in
your locations.conf
You may also be interested in
<https://answers.edge.launchpad.net/bzr/+question/103163>, which has a similar
plugin that does the same for specific file extensions in all branches (rather
than for all files in configured branches).
-Andrew.
More information about the bazaar
mailing list