From: Karl Hasselström Date: Wed, 23 Jul 2008 21:29:09 +0000 (+0200) Subject: Discard stderr output from git apply if the caller wants X-Git-Tag: v0.15-rc1~194 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/29d9a26459c438f4be500022f993b0496d8cbbd8 Discard stderr output from git apply if the caller wants It prints error messages when it fails, and sometimes we don't need to see them since we don't care exactly _why_ it failed. (The only current user does want to see the errors, but future patches will introduce callers that don't.) Signed-off-by: Karl Hasselström --- diff --git a/stgit/commands/edit.py b/stgit/commands/edit.py index a8499c6..3b36a6c 100644 --- a/stgit/commands/edit.py +++ b/stgit/commands/edit.py @@ -96,7 +96,7 @@ def update_patch_description(repository, cd, text): .set_date(gitlib.Date.maybe(authdate)))) failed_diff = None if diff: - tree = repository.apply(cd.parent.data.tree, diff) + tree = repository.apply(cd.parent.data.tree, diff, quiet = False) if tree == None: failed_diff = diff else: diff --git a/stgit/lib/git.py b/stgit/lib/git.py index 6ccdfa7..6929698 100644 --- a/stgit/lib/git.py +++ b/stgit/lib/git.py @@ -483,7 +483,7 @@ class Repository(RunWithEnv): return None finally: index.delete() - def apply(self, tree, patch_text): + def apply(self, tree, patch_text, quiet): """Given a L{Tree} and a patch, will either return the new L{Tree} that results when the patch is applied, or None if the patch couldn't be applied.""" @@ -494,7 +494,7 @@ class Repository(RunWithEnv): try: index.read_tree(tree) try: - index.apply(patch_text) + index.apply(patch_text, quiet) return index.write_tree() except MergeException: return None @@ -552,11 +552,13 @@ class Index(RunWithEnv): """In-index merge, no worktree involved.""" self.run(['git', 'read-tree', '-m', '-i', '--aggressive', base.sha1, ours.sha1, theirs.sha1]).no_output() - def apply(self, patch_text): + def apply(self, patch_text, quiet): """In-index patch application, no worktree involved.""" try: - self.run(['git', 'apply', '--cached'] - ).raw_input(patch_text).no_output() + r = self.run(['git', 'apply', '--cached']).raw_input(patch_text) + if quiet: + r = r.discard_stderr() + r.no_output() except run.RunException: raise MergeException('Patch does not apply cleanly') def delete(self):