summaryrefslogtreecommitdiff
path: root/git/test
diff options
context:
space:
mode:
authorJJ Graham <thetwoj@gmail.com>2019-10-20 19:15:45 -0500
committerSebastian Thiel <sebastian.thiel@icloud.com>2019-10-21 13:10:28 +0200
commita086625da1939d2ccfc0dd27e4d5d63f47c3d2c9 (patch)
tree86f9d68d2a9ae3ba8196b87475eb84dbcdaccbda /git/test
parent544ceecf1a8d397635592d82808d3bb1a6d57e76 (diff)
downloadgitpython-a086625da1939d2ccfc0dd27e4d5d63f47c3d2c9.tar.gz
Added new test to cover the issue this fix addresses (#891)
Diffstat (limited to 'git/test')
-rw-r--r--git/test/test_diff.py50
1 files changed, 48 insertions, 2 deletions
diff --git a/git/test/test_diff.py b/git/test/test_diff.py
index e1b345b5..1bab4510 100644
--- a/git/test/test_diff.py
+++ b/git/test/test_diff.py
@@ -5,12 +5,15 @@
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import ddt
+import shutil
+import tempfile
from git import (
Repo,
GitCommandError,
Diff,
DiffIndex,
NULL_TREE,
+ Submodule,
)
from git.cmd import Git
from git.test.lib import (
@@ -19,7 +22,6 @@ from git.test.lib import (
fixture,
assert_equal,
assert_true,
-
)
from git.test.lib import with_rw_directory
@@ -29,9 +31,15 @@ import os.path as osp
@ddt.ddt
class TestDiff(TestBase):
+ def setUp(self):
+ self.repo_dir = tempfile.mkdtemp()
+ self.submodule_dir = tempfile.mkdtemp()
+
def tearDown(self):
import gc
gc.collect()
+ shutil.rmtree(self.repo_dir)
+ shutil.rmtree(self.submodule_dir)
def _assert_diff_format(self, diffs):
# verify that the format of the diff is sane
@@ -68,7 +76,8 @@ class TestDiff(TestBase):
r.git.commit(all=True, message="change on topic branch")
# there must be a merge-conflict
- self.failUnlessRaises(GitCommandError, r.git.cherry_pick, 'master')
+ with self.assertRaises(GitCommandError):
+ r.git.cherry_pick('master')
# Now do the actual testing - this should just work
self.assertEqual(len(r.index.diff(None)), 2)
@@ -267,6 +276,43 @@ class TestDiff(TestBase):
self.assertIsNone(diff_index[0].a_path, repr(diff_index[0].a_path))
self.assertEqual(diff_index[0].b_path, u'file with spaces', repr(diff_index[0].b_path))
+ def test_diff_submodule(self):
+ """Test that diff is able to correctly diff commits that cover submodule changes"""
+ # Init a temp git repo that will be referenced as a submodule
+ sub = Repo.init(self.submodule_dir)
+ with open(f"{self.submodule_dir}/subfile", "w") as sub_subfile:
+ sub_subfile.write("")
+ sub.index.add(["subfile"])
+ sub.index.commit("first commit")
+
+ # Init a temp git repo that will incorporate the submodule
+ repo = Repo.init(self.repo_dir)
+ with open(f"{self.repo_dir}/test", "w") as foo_test:
+ foo_test.write("")
+ repo.index.add(['test'])
+ Submodule.add(repo, "subtest", "sub", url=f"file://{self.submodule_dir}")
+ repo.index.commit("first commit")
+ repo.create_tag('1')
+
+ # Add a commit to the submodule
+ submodule = repo.submodule('subtest')
+ with open(f"{self.repo_dir}/sub/subfile", "w") as foo_sub_subfile:
+ foo_sub_subfile.write("blub")
+ submodule.module().index.add(["subfile"])
+ submodule.module().index.commit("changed subfile")
+ submodule.binsha = submodule.module().head.commit.binsha
+
+ # Commit submodule updates in parent repo
+ repo.index.add([submodule])
+ repo.index.commit("submodule changed")
+ repo.create_tag('2')
+
+ diff = repo.commit('1').diff(repo.commit('2'))[0]
+ # If diff is unable to find the commit hashes (looks in wrong repo) the *_blob.size
+ # property will be a string containing exception text, an int indicates success
+ self.assertIsInstance(diff.a_blob.size, int)
+ self.assertIsInstance(diff.b_blob.size, int)
+
def test_diff_interface(self):
# test a few variations of the main diff routine
assertion_map = {}