threads / patch / 9810

patchDiscard stderr when determining if a patch is already applied

Subject: [StGit PATCH] Discard stderr when determining if a patch is already applied

## tl;dr

One message between Sep 6, 2007 and Sep 6, 2007. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Karl Hasselström· Sep 6, 2007, 23:50 UTC · lore
An error from git-apply just means that the patch isn't applied.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---

Somewhere in my subprocess refactoring, the discarding of stderr got lost. This patch adds it back to the only place I have discovered so far that actually needs it.

 stgit/git.py |    3 ++-
 stgit/run.py |    9 ++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)
Show changes to 2 files +10 −2

stgit/git.py, stgit/run.py

diff --git a/stgit/git.py b/stgit/git.py
index f847cce..181e10d 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -628,7 +628,8 @@ def apply_diff(rev1, rev2, check_index = True, files = None):
     diff_str = diff(files, rev1, rev2)
     if diff_str:
         try:
-            GRun('git-apply', *index_opt).raw_input(diff_str).no_output()
+            GRun('git-apply', *index_opt).raw_input(
+                diff_str).discard_stderr().no_output()
         except GitRunException:
             return False
 
diff --git a/stgit/run.py b/stgit/run.py
index 29f8f71..7986f3b 100644
--- a/stgit/run.py
+++ b/stgit/run.py
@@ -43,6 +43,7 @@ class Run:
         self.__good_retvals = [0]
         self.__env = None
         self.__indata = None
+        self.__discard_stderr = False
     def __log_start(self):
         if _log_mode == 'debug':
             out.start('Running subprocess %s' % self.__cmd)
@@ -65,11 +66,14 @@ class Run:
         try:
             p = subprocess.Popen(self.__cmd, env = self.__env,
                                  stdin = subprocess.PIPE,
-                                 stdout = subprocess.PIPE)
+                                 stdout = subprocess.PIPE,
+                                 stderr = subprocess.PIPE)
             outdata, errdata = p.communicate(self.__indata)
             self.exitcode = p.returncode
         except OSError, e:
             raise self.exc('%s failed: %s' % (self.__cmd[0], e))
+        if errdata and not self.__discard_stderr:
+            out.err_raw(errdata)
         self.__log_end(self.exitcode)
         self.__check_exitcode()
         return outdata
@@ -87,6 +91,9 @@ class Run:
     def returns(self, retvals):
         self.__good_retvals = retvals
         return self
+    def discard_stderr(self, discard = True):
+        self.__discard_stderr = discard
+        return self
     def env(self, env):
         self.__env = dict(os.environ)
         self.__env.update(env)

← back to recent threads