diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-07-29 15:14:41 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-07-29 15:14:41 +0200 |
commit | 8324c4b38cf37af416833d36696577d8d35dce7f (patch) | |
tree | 9d705ac9c3aee56876895cc9196256f308868045 /git | |
parent | c58887a2d8554d171a7c76b03bfa919c72e918e1 (diff) | |
download | gitpython-8324c4b38cf37af416833d36696577d8d35dce7f.tar.gz |
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 #323
Diffstat (limited to 'git')
-rw-r--r-- | git/diff.py | 4 | ||||
-rw-r--r-- | git/test/test_diff.py | 32 |
2 files changed, 34 insertions, 2 deletions
diff --git a/git/diff.py b/git/diff.py index dc53f3f7..9059091e 100644 --- a/git/diff.py +++ b/git/diff.py @@ -223,12 +223,12 @@ class Diff(object): if a_blob_id is None: self.a_blob = None else: - assert self.a_mode + assert self.a_mode is not None self.a_blob = Blob(repo, hex_to_bin(a_blob_id), mode=self.a_mode, path=a_path) if b_blob_id is None: self.b_blob = None else: - assert self.b_mode + assert self.b_mode is not None self.b_blob = Blob(repo, hex_to_bin(b_blob_id), mode=self.b_mode, path=b_path) self.new_file = new_file diff --git a/git/test/test_diff.py b/git/test/test_diff.py index f2ce1447..53bb65db 100644 --- a/git/test/test_diff.py +++ b/git/test/test_diff.py @@ -4,6 +4,7 @@ # # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php +import os from git.test.lib import ( TestBase, @@ -14,7 +15,11 @@ from git.test.lib import ( ) +from gitdb.test.lib import with_rw_directory + from git import ( + Repo, + GitCommandError, Diff, DiffIndex ) @@ -37,6 +42,33 @@ class TestDiff(TestBase): # END for each diff return diffs + @with_rw_directory + def test_diff_with_staged_file(self, rw_dir): + # SETUP INDEX WITH MULTIPLE STAGES + r = Repo.init(rw_dir) + fp = os.path.join(rw_dir, 'hello.txt') + with open(fp, 'w') as fs: + fs.write("hello world") + r.git.add(fp) + r.git.commit(message="init") + + with open(fp, 'w') as fs: + fs.write("Hola Mundo") + r.git.commit(all=True, message="change on master") + + r.git.checkout('HEAD~1', b='topic') + with open(fp, 'w') as fs: + fs.write("Hallo Welt") + r.git.commit(all=True, message="change on topic branch") + + # there must be a merge-conflict + self.failUnlessRaises(GitCommandError, r.git.cherry_pick, 'master') + + # Now do the actual testing - this should just work + assert len(r.index.diff(None)) == 2 + + assert len(r.index.diff(None, create_patch=True)) == 0, "This should work, but doesn't right now ... it's OK" + def test_list_from_string_new_mode(self): output = StringProcessAdapter(fixture('diff_new_mode')) diffs = Diff._index_from_patch_format(self.rorepo, output.stdout) |