Skip to contentSkip to conversation

Print conflict details with the new infrastructure (bug #11181)

PATCH In review Catalin Marinas 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Print conflict details with the new infrastructure (bug #11181)

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.

---
 stgit/lib/git.py         |   14 +++++++++-----
 stgit/lib/transaction.py |    8 +++++---
 2 files changed, 14 insertions(+), 8 deletions(-)
stgit/lib/git.py +9 -5
index 0a208ef..6457893 100644
@@ -829,12 +829,16 @@ class IndexAndWorktree(RunWithEnvCwd):
                          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')]
+                err = '%d conflict(s)\n%s' \
+                        % (len(conflicts), ''.join(conflicts))
+                raise MergeConflictException(err)
         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
stgit/lib/transaction.py +5 -3
index 0f414d8..b8e82b6 100644
@@ -201,7 +201,8 @@ class StackTransaction(object):
             self.__stack.set_head(new_head, self.__msg)
 
         if self.__error:
-            out.error(self.__error)
+            error_lines = self.__error.split('\n')
+            out.error(*error_lines)
 
         # Write patches.
         def write(msg):
@@ -311,9 +312,10 @@ class StackTransaction(object):
                 tree = iw.index.write_tree()
                 self.__current_tree = tree
                 s = ' (modified)'
-            except git.MergeConflictException:
+            except git.MergeConflictException, e:
                 tree = ours
                 merge_conflict = True
+                conflict_error = str(e)
                 s = ' (conflict)'
             except git.MergeException, e:
                 self.__halt(str(e))
@@ -344,7 +346,7 @@ class StackTransaction(object):
 
             # Save this update so that we can run it a little later.
             self.__conflicting_push = update
-            self.__halt('Merge conflict')
+            self.__halt(conflict_error)
         else:
             # Update immediately.
             update()
#1 lore raw
Quoted 3 lines · Catalin Marinas

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.

Good. But

stgit/lib/transaction.py class StackTransaction(object): · line 205

Quoted 4 lines

if self.__error:

stgit/lib/transaction.py +2 -1
-            out.error(self.__error)
+            error_lines = self.__error.split('\n')
+            out.error(*error_lines)

this feels like something of a hack. Wouldn't it be cleaner to modify MergeConflictException to hold e.g. the set of conflicting filenames, and let it have a method that returned a list of lines? No biggie, though.

Signature · 2 lines
Karl Hasselström, [email protected]
      www.treskal.com/kalle