Skip to content

Commit 8324c4b

Browse files
committed
fix(diff): mode-assertions now deal with 0
If the file was not present, the mode seen in a diff can be legally '0', which previously caused an assertion to fail for no good reason. Now the assertion tests for None instead. Closes gitpython-developers#323
1 parent c58887a commit 8324c4b

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

git/diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ def __init__(self, repo, a_path, b_path, a_blob_id, b_blob_id, a_mode,
223223
if a_blob_id is None:
224224
self.a_blob = None
225225
else:
226-
assert self.a_mode
226+
assert self.a_mode is not None
227227
self.a_blob = Blob(repo, hex_to_bin(a_blob_id), mode=self.a_mode, path=a_path)
228228
if b_blob_id is None:
229229
self.b_blob = None
230230
else:
231-
assert self.b_mode
231+
assert self.b_mode is not None
232232
self.b_blob = Blob(repo, hex_to_bin(b_blob_id), mode=self.b_mode, path=b_path)
233233

234234
self.new_file = new_file

git/test/test_diff.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
7+
import os
78

89
from git.test.lib import (
910
TestBase,
@@ -14,7 +15,11 @@
1415

1516
)
1617

18+
from gitdb.test.lib import with_rw_directory
19+
1720
from git import (
21+
Repo,
22+
GitCommandError,
1823
Diff,
1924
DiffIndex
2025
)
@@ -37,6 +42,33 @@ def _assert_diff_format(self, diffs):
3742
# END for each diff
3843
return diffs
3944

45+
@with_rw_directory
46+
def test_diff_with_staged_file(self, rw_dir):
47+
# SETUP INDEX WITH MULTIPLE STAGES
48+
r = Repo.init(rw_dir)
49+
fp = os.path.join(rw_dir, 'hello.txt')
50+
with open(fp, 'w') as fs:
51+
fs.write("hello world")
52+
r.git.add(fp)
53+
r.git.commit(message="init")
54+
55+
with open(fp, 'w') as fs:
56+
fs.write("Hola Mundo")
57+
r.git.commit(all=True, message="change on master")
58+
59+
r.git.checkout('HEAD~1', b='topic')
60+
with open(fp, 'w') as fs:
61+
fs.write("Hallo Welt")
62+
r.git.commit(all=True, message="change on topic branch")
63+
64+
# there must be a merge-conflict
65+
self.failUnlessRaises(GitCommandError, r.git.cherry_pick, 'master')
66+
67+
# Now do the actual testing - this should just work
68+
assert len(r.index.diff(None)) == 2
69+
70+
assert len(r.index.diff(None, create_patch=True)) == 0, "This should work, but doesn't right now ... it's OK"
71+
4072
def test_list_from_string_new_mode(self):
4173
output = StringProcessAdapter(fixture('diff_new_mode'))
4274
diffs = Diff._index_from_patch_format(self.rorepo, output.stdout)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy