{"thread":{"id":"16587","subject":"[StGit PATCH] Print conflict details with the new infrastructure (bug #11181)","startedAt":"2008-12-03T21:38:13Z","lastAt":"2008-12-04T09:30:11Z","messageCount":2,"participants":["Catalin Marinas","Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"97099","messageId":"20081203213813.9924.62751.stgit@localhost.localdomain","threadId":"16587","inReplyTo":null,"subject":"[StGit PATCH] Print conflict details with the new infrastructure (bug #11181)","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2008-12-03T21:38:13Z","receivedAt":"2008-12-03T21:38:13Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"The patch modifies the IndexAndWorkTree.merge() function to display\npass the conflict information (files) when raising an exception. The\nlogic is similar to the one in the old infrastructure.\n\nSigned-off-by: Catalin Marinas <catalin.marinas@gmail.com>\n---\n stgit/lib/git.py         |   15 ++++++++++-----\n stgit/lib/transaction.py |   11 ++++++++---\n 2 files changed, 18 insertions(+), 8 deletions(-)\n\ndiff --git a/stgit/lib/git.py b/stgit/lib/git.py\nindex 0a208ef..e2b4266 100644\n--- a/stgit/lib/git.py\n+++ b/stgit/lib/git.py\n@@ -677,6 +677,9 @@ class MergeException(exception.StgException):\n \n class MergeConflictException(MergeException):\n     \"\"\"Exception raised when a merge fails due to conflicts.\"\"\"\n+    def __init__(self, conflicts):\n+        MergeException.__init__(self)\n+        self.conflicts = conflicts\n \n class Index(RunWithEnv):\n     \"\"\"Represents a git index file.\"\"\"\n@@ -829,12 +832,14 @@ class IndexAndWorktree(RunWithEnvCwd):\n                          env = { 'GITHEAD_%s' % base.sha1: 'ancestor',\n                                  'GITHEAD_%s' % ours.sha1: 'current',\n                                  'GITHEAD_%s' % theirs.sha1: 'patched'})\n-            r.discard_output()\n+            r.returns([0, 1])\n+            output = r.output_lines()\n+            if r.exitcode:\n+                # There were conflicts\n+                conflicts = [l for l in output if l.startswith('CONFLICT')]\n+                raise MergeConflictException(conflicts)\n         except run.RunException, e:\n-            if r.exitcode == 1:\n-                raise MergeConflictException()\n-            else:\n-                raise MergeException('Index/worktree dirty')\n+            raise MergeException('Index/worktree dirty')\n     def changed_files(self, tree, pathlimits = []):\n         \"\"\"Return the set of files in the worktree that have changed with\n         respect to C{tree}. The listing is optionally restricted to\ndiff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py\nindex 0f414d8..54de127 100644\n--- a/stgit/lib/transaction.py\n+++ b/stgit/lib/transaction.py\n@@ -94,6 +94,7 @@ class StackTransaction(object):\n         self.__base = self.__stack.base\n         self.__discard_changes = discard_changes\n         self.__bad_head = None\n+        self.__conflicts = None\n         if isinstance(allow_conflicts, bool):\n             self.__allow_conflicts = lambda trans: allow_conflicts\n         else:\n@@ -201,7 +202,10 @@ class StackTransaction(object):\n             self.__stack.set_head(new_head, self.__msg)\n \n         if self.__error:\n-            out.error(self.__error)\n+            if self.__conflicts:\n+                out.error(*([self.__error] + self.__conflicts))\n+            else:\n+                out.error(self.__error)\n \n         # Write patches.\n         def write(msg):\n@@ -311,9 +315,10 @@ class StackTransaction(object):\n                 tree = iw.index.write_tree()\n                 self.__current_tree = tree\n                 s = ' (modified)'\n-            except git.MergeConflictException:\n+            except git.MergeConflictException, e:\n                 tree = ours\n                 merge_conflict = True\n+                self.__conflicts = e.conflicts\n                 s = ' (conflict)'\n             except git.MergeException, e:\n                 self.__halt(str(e))\n@@ -344,7 +349,7 @@ class StackTransaction(object):\n \n             # Save this update so that we can run it a little later.\n             self.__conflicting_push = update\n-            self.__halt('Merge conflict')\n+            self.__halt(\"%d merge conflict(s)\" % len(self.__conflicts))\n         else:\n             # Update immediately.\n             update()\n"},{"id":"97137","messageId":"20081204093011.GA25060@diana.vm.bytemark.co.uk","threadId":"16587","inReplyTo":"20081203213813.9924.62751.stgit@localhost.localdomain","subject":"Re: [StGit PATCH] Print conflict details with the new infrastructure (bug #11181)","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-12-04T09:30:11Z","receivedAt":"2008-12-04T09:30:11Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-12-03 21:38:13 +0000, Catalin Marinas wrote:\n\n> The patch modifies the IndexAndWorkTree.merge() function to display\n> pass the conflict information (files) when raising an exception. The\n> logic is similar to the one in the old infrastructure.\n\nLooks good. Thanks.\n\n> Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>\n\nAcked-by: Karl Hasselström <kha@treskal.com>\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}