The patch modifies the IndexAndWorkTree.merge() function to display
pass the conflict information (files) when raising an exception. The
logic is similar to the one in the old infrastructure.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
Acked-by: Karl Hasselström <kha@treskal.com>
class MergeConflictException(MergeException):
"""Exception raised when a merge fails due to conflicts."""
class MergeConflictException(MergeException):
"""Exception raised when a merge fails due to conflicts."""
+ def __init__(self, conflicts):
+ MergeException.__init__(self)
+ self.conflicts = conflicts
class Index(RunWithEnv):
"""Represents a git index file."""
class Index(RunWithEnv):
"""Represents a git index file."""
env = { 'GITHEAD_%s' % base.sha1: 'ancestor',
'GITHEAD_%s' % ours.sha1: 'current',
'GITHEAD_%s' % theirs.sha1: 'patched'})
env = { 'GITHEAD_%s' % base.sha1: 'ancestor',
'GITHEAD_%s' % ours.sha1: 'current',
'GITHEAD_%s' % theirs.sha1: 'patched'})
+ r.returns([0, 1])
+ output = r.output_lines()
+ if r.exitcode:
+ # There were conflicts
+ conflicts = [l for l in output if l.startswith('CONFLICT')]
+ raise MergeConflictException(conflicts)
except run.RunException, e:
except run.RunException, e:
- if r.exitcode == 1:
- raise MergeConflictException()
- else:
- raise MergeException('Index/worktree dirty')
+ raise MergeException('Index/worktree dirty')
def changed_files(self, tree, pathlimits = []):
"""Return the set of files in the worktree that have changed with
respect to C{tree}. The listing is optionally restricted to
def changed_files(self, tree, pathlimits = []):
"""Return the set of files in the worktree that have changed with
respect to C{tree}. The listing is optionally restricted to
self.__base = self.__stack.base
self.__discard_changes = discard_changes
self.__bad_head = None
self.__base = self.__stack.base
self.__discard_changes = discard_changes
self.__bad_head = None
+ self.__conflicts = None
if isinstance(allow_conflicts, bool):
self.__allow_conflicts = lambda trans: allow_conflicts
else:
if isinstance(allow_conflicts, bool):
self.__allow_conflicts = lambda trans: allow_conflicts
else:
self.__stack.set_head(new_head, self.__msg)
if self.__error:
self.__stack.set_head(new_head, self.__msg)
if self.__error:
- out.error(self.__error)
+ if self.__conflicts:
+ out.error(*([self.__error] + self.__conflicts))
+ else:
+ out.error(self.__error)
# Write patches.
def write(msg):
# Write patches.
def write(msg):
tree = iw.index.write_tree()
self.__current_tree = tree
s = ' (modified)'
tree = iw.index.write_tree()
self.__current_tree = tree
s = ' (modified)'
- except git.MergeConflictException:
+ except git.MergeConflictException, e:
tree = ours
merge_conflict = True
tree = ours
merge_conflict = True
+ self.__conflicts = e.conflicts
s = ' (conflict)'
except git.MergeException, e:
self.__halt(str(e))
s = ' (conflict)'
except git.MergeException, e:
self.__halt(str(e))
# Save this update so that we can run it a little later.
self.__conflicting_push = update
# Save this update so that we can run it a little later.
self.__conflicting_push = update
- self.__halt('Merge conflict')
+ self.__halt("%d merge conflict(s)" % len(self.__conflicts))
else:
# Update immediately.
update()
else:
# Update immediately.
update()