Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita086625

Browse files
thetwojByron
authored andcommitted
Added new test to cover the issue this fix addresses (#891)
1 parent544ceec commita086625

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

‎git/test/test_diff.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
77
importddt
8+
importshutil
9+
importtempfile
810
fromgitimport (
911
Repo,
1012
GitCommandError,
1113
Diff,
1214
DiffIndex,
1315
NULL_TREE,
16+
Submodule,
1417
)
1518
fromgit.cmdimportGit
1619
fromgit.test.libimport (
@@ -19,7 +22,6 @@
1922
fixture,
2023
assert_equal,
2124
assert_true,
22-
2325
)
2426
fromgit.test.libimportwith_rw_directory
2527

@@ -29,9 +31,15 @@
2931
@ddt.ddt
3032
classTestDiff(TestBase):
3133

34+
defsetUp(self):
35+
self.repo_dir=tempfile.mkdtemp()
36+
self.submodule_dir=tempfile.mkdtemp()
37+
3238
deftearDown(self):
3339
importgc
3440
gc.collect()
41+
shutil.rmtree(self.repo_dir)
42+
shutil.rmtree(self.submodule_dir)
3543

3644
def_assert_diff_format(self,diffs):
3745
# verify that the format of the diff is sane
@@ -68,7 +76,8 @@ def test_diff_with_staged_file(self, rw_dir):
6876
r.git.commit(all=True,message="change on topic branch")
6977

7078
# there must be a merge-conflict
71-
self.failUnlessRaises(GitCommandError,r.git.cherry_pick,'master')
79+
withself.assertRaises(GitCommandError):
80+
r.git.cherry_pick('master')
7281

7382
# Now do the actual testing - this should just work
7483
self.assertEqual(len(r.index.diff(None)),2)
@@ -267,6 +276,43 @@ def test_diff_with_spaces(self):
267276
self.assertIsNone(diff_index[0].a_path,repr(diff_index[0].a_path))
268277
self.assertEqual(diff_index[0].b_path,u'file with spaces',repr(diff_index[0].b_path))
269278

279+
deftest_diff_submodule(self):
280+
"""Test that diff is able to correctly diff commits that cover submodule changes"""
281+
# Init a temp git repo that will be referenced as a submodule
282+
sub=Repo.init(self.submodule_dir)
283+
withopen(f"{self.submodule_dir}/subfile","w")assub_subfile:
284+
sub_subfile.write("")
285+
sub.index.add(["subfile"])
286+
sub.index.commit("first commit")
287+
288+
# Init a temp git repo that will incorporate the submodule
289+
repo=Repo.init(self.repo_dir)
290+
withopen(f"{self.repo_dir}/test","w")asfoo_test:
291+
foo_test.write("")
292+
repo.index.add(['test'])
293+
Submodule.add(repo,"subtest","sub",url=f"file://{self.submodule_dir}")
294+
repo.index.commit("first commit")
295+
repo.create_tag('1')
296+
297+
# Add a commit to the submodule
298+
submodule=repo.submodule('subtest')
299+
withopen(f"{self.repo_dir}/sub/subfile","w")asfoo_sub_subfile:
300+
foo_sub_subfile.write("blub")
301+
submodule.module().index.add(["subfile"])
302+
submodule.module().index.commit("changed subfile")
303+
submodule.binsha=submodule.module().head.commit.binsha
304+
305+
# Commit submodule updates in parent repo
306+
repo.index.add([submodule])
307+
repo.index.commit("submodule changed")
308+
repo.create_tag('2')
309+
310+
diff=repo.commit('1').diff(repo.commit('2'))[0]
311+
# If diff is unable to find the commit hashes (looks in wrong repo) the *_blob.size
312+
# property will be a string containing exception text, an int indicates success
313+
self.assertIsInstance(diff.a_blob.size,int)
314+
self.assertIsInstance(diff.b_blob.size,int)
315+
270316
deftest_diff_interface(self):
271317
# test a few variations of the main diff routine
272318
assertion_map= {}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp