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."""
env = { 'GITHEAD_%s' % base.sha1: 'ancestor',
'GITHEAD_%s' % ours.sha1: 'current',
'GITHEAD_%s' % theirs.sha1: 'patched'})
- r.discard_output()
+ 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:
- 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
repository.run(['git', 'branch', create_at.sha1]).discard_output()
return cls(repository, name)
+
+def diffstat(diff):
+ """Return the diffstat of the supplied diff."""
+ return run.Run('git', 'apply', '--stat', '--summary'
+ ).raw_input(diff).raw_output()