Use the output from merge-recursive to list conflicts
authorDavid Kågedal <david@virtutech.com>
Wed, 19 Dec 2007 18:00:12 +0000 (18:00 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Wed, 19 Dec 2007 23:13:30 +0000 (23:13 +0000)
merge-recursive already has useful information about what the conflicts
were, so we reuse that when pushing.

Signed-off-by: David Kågedal <davidk@lysator.liu.se>
Signed-off-by: Karl Hasselström <kha@treskal.com>
stgit/git.py
stgit/stack.py

index bc9bb4b..659bd7b 100644 (file)
@@ -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
index d4ea802..3468547 100644 (file)
@@ -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'