Skip to content

Split diff line by '\t' for metadata and path #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Split diff line by '\t' for metadata and path
This protects against `.split(None)` which uses consecutive whitespace
as a separator to overlook paths where a single space is the filename.
For example, in this diff line:

line = ':100644 000000 e69de29
0000000000000000000000000000000000000000 D       '

The deleted file is a file named ' ' (just one space).  It's entirely
possible to commit this, remove, and to 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.
  • Loading branch information
jonathanchu committed Mar 15, 2016
commit 25f27c86af9901f0135eac20a37573469a9c26ef
3 changes: 2 additions & 1 deletion git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ def _index_from_raw_format(cls, repo, stream):
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
Expand Down