{"thread":{"id":"9810","subject":"[StGit PATCH] Discard stderr when determining if a patch is already applied","startedAt":"2007-09-06T23:50:48Z","lastAt":"2007-09-06T23:50:48Z","messageCount":1,"participants":["Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"52820","messageId":"20070906234906.15591.33653.stgit@yoghurt","threadId":"9810","inReplyTo":null,"subject":"[StGit PATCH] Discard stderr when determining if a patch is already applied","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-09-06T23:50:48Z","receivedAt":"2007-09-06T23:50:48Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"An error from git-apply just means that the patch isn't applied.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\nSomewhere in my subprocess refactoring, the discarding of stderr got\nlost. This patch adds it back to the only place I have discovered so\nfar that actually needs it.\n\n stgit/git.py |    3 ++-\n stgit/run.py |    9 ++++++++-\n 2 files changed, 10 insertions(+), 2 deletions(-)\n\n\ndiff --git a/stgit/git.py b/stgit/git.py\nindex f847cce..181e10d 100644\n--- a/stgit/git.py\n+++ b/stgit/git.py\n@@ -628,7 +628,8 @@ def apply_diff(rev1, rev2, check_index = True, files = None):\n     diff_str = diff(files, rev1, rev2)\n     if diff_str:\n         try:\n-            GRun('git-apply', *index_opt).raw_input(diff_str).no_output()\n+            GRun('git-apply', *index_opt).raw_input(\n+                diff_str).discard_stderr().no_output()\n         except GitRunException:\n             return False\n \ndiff --git a/stgit/run.py b/stgit/run.py\nindex 29f8f71..7986f3b 100644\n--- a/stgit/run.py\n+++ b/stgit/run.py\n@@ -43,6 +43,7 @@ class Run:\n         self.__good_retvals = [0]\n         self.__env = None\n         self.__indata = None\n+        self.__discard_stderr = False\n     def __log_start(self):\n         if _log_mode == 'debug':\n             out.start('Running subprocess %s' % self.__cmd)\n@@ -65,11 +66,14 @@ class Run:\n         try:\n             p = subprocess.Popen(self.__cmd, env = self.__env,\n                                  stdin = subprocess.PIPE,\n-                                 stdout = subprocess.PIPE)\n+                                 stdout = subprocess.PIPE,\n+                                 stderr = subprocess.PIPE)\n             outdata, errdata = p.communicate(self.__indata)\n             self.exitcode = p.returncode\n         except OSError, e:\n             raise self.exc('%s failed: %s' % (self.__cmd[0], e))\n+        if errdata and not self.__discard_stderr:\n+            out.err_raw(errdata)\n         self.__log_end(self.exitcode)\n         self.__check_exitcode()\n         return outdata\n@@ -87,6 +91,9 @@ class Run:\n     def returns(self, retvals):\n         self.__good_retvals = retvals\n         return self\n+    def discard_stderr(self, discard = True):\n+        self.__discard_stderr = discard\n+        return self\n     def env(self, env):\n         self.__env = dict(os.environ)\n         self.__env.update(env)\n"}]}