From: David Kågedal Date: Wed, 19 Dec 2007 18:00:12 +0000 (+0000) Subject: Use the output from merge-recursive to list conflicts X-Git-Tag: v0.15-rc1~337 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/6c76a03347dca249ac12f791d6321ff15889c64a Use the output from merge-recursive to list conflicts merge-recursive already has useful information about what the conflicts were, so we reuse that when pushing. Signed-off-by: David Kågedal Signed-off-by: Karl Hasselström --- diff --git a/stgit/git.py b/stgit/git.py index bc9bb4b..659bd7b 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -43,6 +43,14 @@ class GRun(Run): """ Run.__init__(self, 'git', *cmd) +class GitConflictException(GitException): + def __init__(self, conflicts): + GitException.__init__(self) + self.conflicts = conflicts + def __str__(self): + return "%d conflicts" % len(self.conflicts) + def list(self): + out.info(*self.conflicts) # # Classes @@ -702,13 +710,15 @@ def merge_recursive(base, head1, head2): local tree """ refresh_index() - - # use _output() to mask the verbose prints of the tool - try: - # discard output to mask the verbose prints of the tool - GRun('merge-recursive', base, '--', head1, head2).discard_output() - except GitRunException, ex: - raise GitException, 'GIT index merging failed (possible conflicts)' + p = GRun('merge-recursive', base, '--', head1, head2).returns([0, 1]) + output = p.output_lines() + if p.exitcode == 0: + # No problems + return + else: # exitcode == 1 + # There were conflicts + conflicts = [l.strip() for l in output if l.startswith('CONFLICT')] + raise GitConflictException(conflicts) def merge(base, head1, head2): """Perform a 3-way merge between base, head1 and head2 into the diff --git a/stgit/stack.py b/stgit/stack.py index d4ea802..3468547 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -1105,6 +1105,8 @@ class Series(PatchSet): # merge can fail but the patch needs to be pushed try: git.merge_recursive(bottom, head, top) + except git.GitConflictException, ex: + ex.list() except git.GitException, ex: out.error('The merge failed during "push".', 'Use "refresh" after fixing the conflicts or'