Skip to content

Commit 59cc3bb

Browse files
puneetdixit200codex
andcommitted
fix: preserve diff process stderr
Co-authored-by: OpenAI Codex <codex@openai.com>
1 parent da07a64 commit 59cc3bb

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

git/diff.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,14 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn
602602

603603
# FIXME: Here SLURPING raw, need to re-phrase header-regexes linewise.
604604
text_list: List[bytes] = []
605-
handle_process_output(proc, text_list.append, None, finalize_process, decode_streams=False)
605+
stderr_list: List[bytes] = []
606+
607+
def finalize_process_with_stderr(proc: Union["Popen", "Git.AutoInterrupt"]) -> None:
608+
finalize_process(proc, stderr=b"".join(stderr_list))
609+
610+
handle_process_output(
611+
proc, text_list.append, stderr_list.append, finalize_process_with_stderr, decode_streams=False
612+
)
606613

607614
# For now, we have to bake the stream.
608615
text = b"".join(text_list)
@@ -768,11 +775,16 @@ def _index_from_raw_format(cls, repo: "Repo", proc: "Popen") -> "DiffIndex[Diff]
768775
# :100644 100644 687099101... 37c5e30c8... M .gitignore
769776

770777
index: "DiffIndex" = DiffIndex()
778+
stderr_list: List[bytes] = []
779+
780+
def finalize_process_with_stderr(proc: Union["Popen", "Git.AutoInterrupt"]) -> None:
781+
finalize_process(proc, stderr=b"".join(stderr_list))
782+
771783
handle_process_output(
772784
proc,
773785
lambda byt: cls._handle_diff_line(byt, repo, index),
774-
None,
775-
finalize_process,
786+
stderr_list.append,
787+
finalize_process_with_stderr,
776788
decode_streams=False,
777789
)
778790

test/test_index.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,10 @@ def test_index_file_diff_null_tree_with_initial_index(self, rw_dir):
585585
self.assertEqual(len(patch), 1)
586586
self.assertIn(b"+# Initial file", patch[0].diff)
587587

588+
with self.assertRaises(GitCommandError) as exc_info:
589+
index.diff(NULL_TREE, bogus_option=True)
590+
self.assertIn("usage: git diff", exc_info.exception.stderr)
591+
588592
def _count_existing(self, repo, files):
589593
"""Return count of files that actually exist in the repository directory."""
590594
existing = 0

0 commit comments

Comments
 (0)