Skip to content

Fix repo.index.diff("HEAD", create_patch=True) always returning an empty list #948

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
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class Diff(object):
# precompiled regex
re_header = re.compile(br"""
^diff[ ]--git
[ ](?P<a_path_fallback>"?a/.+?"?)[ ](?P<b_path_fallback>"?b/.+?"?)\n
[ ](?P<a_path_fallback>"?[ab]/.+?"?)[ ](?P<b_path_fallback>"?[ab]/.+?"?)\n
(?:^old[ ]mode[ ](?P<old_mode>\d+)\n
^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))?
(?:^similarity[ ]index[ ]\d+%\n
Expand Down
7 changes: 6 additions & 1 deletion git/test/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ def test_diff_with_staged_file(self, rw_dir):

with open(fp, 'w') as fs:
fs.write("Hola Mundo")
r.git.commit(all=True, message="change on master")
r.git.add(Git.polish_url(fp))
self.assertEqual(len(r.index.diff("HEAD", create_patch=True)), 1,
"create_patch should generate patch of diff to HEAD")
r.git.commit(message="change on master")
self.assertEqual(len(r.index.diff("HEAD", create_patch=True)), 0,
"create_patch should generate no patch, already on HEAD")

r.git.checkout('HEAD~1', b='topic')
with open(fp, 'w') as fs:
Expand Down