{"thread":{"id":"16557","subject":"[StGit PATCH] Print conflict details with the new infrastructure (bug #11181)","startedAt":"2008-12-02T14:40:45Z","lastAt":"2008-12-02T15:43:59Z","messageCount":2,"participants":["Catalin Marinas","Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"96945","messageId":"20081202144045.24372.69278.stgit@localhost.localdomain","threadId":"16557","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-02T14:40:45Z","receivedAt":"2008-12-02T14:40:45Z","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         |   14 +++++++++-----\n stgit/lib/transaction.py |    8 +++++---\n 2 files changed, 14 insertions(+), 8 deletions(-)\n\ndiff --git a/stgit/lib/git.py b/stgit/lib/git.py\nindex 0a208ef..6457893 100644\n--- a/stgit/lib/git.py\n+++ b/stgit/lib/git.py\n@@ -829,12 +829,16 @@ 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+                err = '%d conflict(s)\\n%s' \\\n+                        % (len(conflicts), ''.join(conflicts))\n+                raise MergeConflictException(err)\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..b8e82b6 100644\n--- a/stgit/lib/transaction.py\n+++ b/stgit/lib/transaction.py\n@@ -201,7 +201,8 @@ class StackTransaction(object):\n             self.__stack.set_head(new_head, self.__msg)\n \n         if self.__error:\n-            out.error(self.__error)\n+            error_lines = self.__error.split('\\n')\n+            out.error(*error_lines)\n \n         # Write patches.\n         def write(msg):\n@@ -311,9 +312,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+                conflict_error = str(e)\n                 s = ' (conflict)'\n             except git.MergeException, e:\n                 self.__halt(str(e))\n@@ -344,7 +346,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(conflict_error)\n         else:\n             # Update immediately.\n             update()\n"},{"id":"96954","messageId":"20081202154359.GB19967@diana.vm.bytemark.co.uk","threadId":"16557","inReplyTo":"20081202144045.24372.69278.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-02T15:43:59Z","receivedAt":"2008-12-02T15:43:59Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On 2008-12-02 14:40:45 +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\nGood. But\n\n>          if self.__error:\n> -            out.error(self.__error)\n> +            error_lines = self.__error.split('\\n')\n> +            out.error(*error_lines)\n\nthis feels like something of a hack. Wouldn't it be cleaner to modify\nMergeConflictException to hold e.g. the set of conflicting filenames,\nand let it have a method that returned a list of lines? No biggie,\nthough.\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"}]}