nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gitpython-developers/GitPython
Pull request #398 (2016-03-15 18:20:25)

Split diff line by '\t' for metadata and path
#### What's this PR do?
This protects against `.split(None)`, which uses consecutive whitespace as a separator and may overlook paths where a single space is the filename.  While having a filename consisting of only a single space is unlikely in practical usage, it is entirely possible.

For example, take this diff line:

<img width="657" alt="screenshot 2016-03-15 14 18 42" src="https://cloud.githubusercontent.com/assets/66164/13789088/e69b89dc-eab8-11e5-9fa3-4e2d72992992.png">

Notice there is a tab after the `change_type` and a space for the path.  The deleted file is a file named ' ' (just one space) at the git root.  To replicate this issue, add and commit this file, then delete and commit.  This will produce the following output from `git diff`:

```
$ git diff --name-status <SHA1> <SHA2>
D
M       path/to/another/file.py
...
```

This would cause the initial `.split(None, 5)` to fail as it will count all consecutive whitespace as a separator, disregarding the ' ' (single space)  filename.


Patch:
diff --git a/git/diff.py b/git/diff.py
index 9059091e..062220df 100644
--- a/git/diff.py
+++ b/git/diff.py
@@ -365,7 +365,8 @@ class Diff(object):
             if not line.startswith(":"):
                 continue
             # END its not a valid diff line
-            old_mode, new_mode, a_blob_id, b_blob_id, change_type, path = line[1:].split(None, 5)
+            meta, _, path = line[1:].partition('\t')
+            old_mode, new_mode, a_blob_id, b_blob_id, change_type = meta.split(None, 4)
             path = path.strip()
             a_path = path
             b_path = path


Test patch:
diff --git a/git/test/fixtures/diff_index_raw b/git/test/fixtures/diff_index_raw
new file mode 100644
index 00000000..c25f380d
--- /dev/null
+++ b/git/test/fixtures/diff_index_raw
@@ -0,0 +1,1 @@
+:100644 000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 D	 
diff --git a/git/test/test_diff.py b/git/test/test_diff.py
index 53bb65db..b0d98248 100644
--- a/git/test/test_diff.py
+++ b/git/test/test_diff.py
@@ -122,6 +122,12 @@ class TestDiff(TestBase):
         dr = res[3]
         assert dr.diff.endswith(b"+Binary files a/rps and b/rps differ\n")
 
+    def test_diff_index_raw_format(self):
+        output = StringProcessAdapter(fixture('diff_index_raw'))
+        res = Diff._index_from_raw_format(None, output.stdout)
+        assert res[0].deleted_file
+        assert res[0].b_path == ''
+
     def test_diff_patch_format(self):
         # test all of the 'old' format diffs for completness - it should at least
         # be able to deal with it