1
# Copyright (C) 2005, 2006, 2007, 2009, 2010 Canonical Ltd
1
# Copyright (C) 2005, 2007, 2009 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
81
81
resolve_action_registry.register(
82
82
'done', 'done', 'Marks the conflict as resolved' )
83
83
resolve_action_registry.register(
84
'take-this', 'take_this',
84
'keep-mine', 'keep_mine',
85
85
'Resolve the conflict preserving the version in the working tree' )
86
86
resolve_action_registry.register(
87
'take-other', 'take_other',
87
'take-theirs', 'take_theirs',
88
88
'Resolve the conflict taking the merged version into account' )
89
89
resolve_action_registry.default_key = 'done'
408
408
:param tree: The tree passed as a parameter to the method.
410
meth = getattr(self, 'action_%s' % action, None)
410
meth = getattr(self, action, None)
412
412
raise NotImplementedError(self.__class__.__name__ + '.' + action)
415
def associated_filenames(self):
416
"""The names of the files generated to help resolve the conflict."""
417
raise NotImplementedError(self.associated_filenames)
419
415
def cleanup(self, tree):
420
for fname in self.associated_filenames():
422
osutils.delete_any(tree.abspath(fname))
424
if e.errno != errno.ENOENT:
416
raise NotImplementedError(self.cleanup)
427
def action_done(self, tree):
418
def done(self, tree):
428
419
"""Mark the conflict as solved once it has been handled."""
429
420
# This method does nothing but simplifies the design of upper levels.
432
def action_take_this(self, tree):
433
raise NotImplementedError(self.action_take_this)
423
def keep_mine(self, tree):
424
raise NotImplementedError(self.keep_mine)
435
def action_take_other(self, tree):
436
raise NotImplementedError(self.action_take_other)
426
def take_theirs(self, tree):
427
raise NotImplementedError(self.take_theirs)
439
430
class PathConflict(Conflict):
455
446
s.add('conflict_path', self.conflict_path)
458
def associated_filenames(self):
449
def cleanup(self, tree):
459
450
# No additional files have been generated here
462
def action_take_this(self, tree):
453
def keep_mine(self, tree):
463
454
tree.rename_one(self.conflict_path, self.path)
465
def action_take_other(self, tree):
456
def take_theirs(self, tree):
466
457
# just acccept bzr proposal
477
468
format = 'Contents conflict in %(path)s'
479
def associated_filenames(self):
480
return [self.path + suffix for suffix in ('.BASE', '.OTHER')]
470
def cleanup(self, tree):
471
for suffix in ('.BASE', '.OTHER'):
473
osutils.delete_any(tree.abspath(self.path + suffix))
475
if e.errno != errno.ENOENT:
482
478
# FIXME: I smell something weird here and it seems we should be able to be
483
479
# more coherent with some other conflict ? bzr *did* a choice there but
484
# neither action_take_this nor action_take_other reflect that...
486
def action_take_this(self, tree):
480
# neither keep_mine nor take_theirs reflect that... -- vila 091224
481
def keep_mine(self, tree):
487
482
tree.remove([self.path + '.OTHER'], force=True, keep_files=False)
489
def action_take_other(self, tree):
484
def take_theirs(self, tree):
490
485
tree.remove([self.path], force=True, keep_files=False)
506
501
format = 'Text conflict in %(path)s'
508
def associated_filenames(self):
509
return [self.path + suffix for suffix in CONFLICT_SUFFIXES]
503
def cleanup(self, tree):
504
for suffix in CONFLICT_SUFFIXES:
506
osutils.delete_any(tree.abspath(self.path+suffix))
508
if e.errno != errno.ENOENT:
512
512
class HandledConflict(Conflict):
528
528
s.add('action', self.action)
531
def associated_filenames(self):
532
# Nothing has been generated here
531
def cleanup(self, tree):
532
"""Nothing to cleanup."""
536
536
class HandledPathConflict(HandledConflict):
579
579
format = 'Conflict adding file %(conflict_path)s. %(action)s %(path)s.'
581
def action_take_this(self, tree):
581
def keep_mine(self, tree):
582
582
tree.remove([self.conflict_path], force=True, keep_files=False)
583
583
tree.rename_one(self.path, self.conflict_path)
585
def action_take_other(self, tree):
585
def take_theirs(self, tree):
586
586
tree.remove([self.path], force=True, keep_files=False)
602
602
format = 'Conflict moving %(conflict_path)s into %(path)s. %(action)s.'
604
def action_take_this(self, tree):
604
def keep_mine(self, tree):
605
605
# just acccept bzr proposal
608
def action_take_other(self, tree):
608
def take_theirs(self, tree):
609
609
# FIXME: We shouldn't have to manipulate so many paths here (and there
610
610
# is probably a bug or two...)
611
611
base_path = osutils.basename(self.path)
637
637
# FIXME: We silently do nothing to make tests pass, but most probably the
638
638
# conflict shouldn't exist (the long story is that the conflict is
639
639
# generated with another one that can be resolved properly) -- vila 091224
640
def action_take_this(self, tree):
640
def keep_mine(self, tree):
643
def action_take_other(self, tree):
643
def take_theirs(self, tree):
656
656
format = 'Conflict adding files to %(path)s. %(action)s.'
658
def action_take_this(self, tree):
658
def keep_mine(self, tree):
659
659
tree.remove([self.path], force=True, keep_files=False)
661
def action_take_other(self, tree):
661
def take_theirs(self, tree):
662
662
# just acccept bzr proposal
677
677
# FIXME: It's a bit strange that the default action is not coherent with
678
678
# MissingParent from the *user* pov.
680
def action_take_this(self, tree):
680
def keep_mine(self, tree):
681
681
# just acccept bzr proposal
684
def action_take_other(self, tree):
684
def take_theirs(self, tree):
685
685
tree.remove([self.path], force=True, keep_files=False)
695
695
format = "Conflict: %(path)s is not a directory, but has files in it."\
698
# FIXME: .OTHER should be used instead of .new when the conflict is created
700
def action_take_this(self, tree):
698
def keep_mine(self, tree):
701
699
# FIXME: we should preserve that path when the conflict is generated !
702
700
if self.path.endswith('.new'):
703
701
conflict_path = self.path[:-(len('.new'))]
704
702
tree.remove([self.path], force=True, keep_files=False)
705
703
tree.add(conflict_path)
707
raise NotImplementedError(self.action_take_this)
705
raise NotImplementedError(self.keep_mine)
709
def action_take_other(self, tree):
707
def take_theirs(self, tree):
710
708
# FIXME: we should preserve that path when the conflict is generated !
711
709
if self.path.endswith('.new'):
712
710
conflict_path = self.path[:-(len('.new'))]
713
711
tree.remove([conflict_path], force=True, keep_files=False)
714
712
tree.rename_one(self.path, conflict_path)
716
raise NotImplementedError(self.action_take_other)
714
raise NotImplementedError(self.take_theirs)