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

Commit61dbe88

Browse files
committed
Fixing recursion issue introduced with submodule support
1 parentcfd2121 commit61dbe88

File tree

7 files changed

+160
-3
lines changed

7 files changed

+160
-3
lines changed

‎lib/git/submodule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Submodule(object):
2929
"""
3030

3131
def__init__(self,repo=None,id=None,mode=None,name='',
32-
commit_context=None,path=''):
32+
commit_context='',path=''):
3333
"""
3434
Initialize a newly instanced Submodule
3535

‎lib/git/tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
importsubmodule
1111

1212
classTree(LazyMixin):
13-
def__init__(self,repo,id,mode=None,name=None,commit_context=None,path=''):
13+
def__init__(self,repo,id,mode=None,name=None,commit_context='',path=''):
1414
LazyMixin.__init__(self)
1515
self.repo=repo
1616
self.id=id
24.7 KB
Binary file not shown.

‎test/git/.directory

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[Dolphin]
2+
Timestamp=2010,10,28,0,8,28
3+
ViewMode=1

‎test/git/test_submodule.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# test_submodule.py
2+
# Copyright (C) 2008-2010 Michael Trier (mtrier@gmail.com) and contributors
3+
#
4+
# This module is part of GitPython and is released under
5+
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6+
7+
importos.path
8+
importsys
9+
10+
execpath=os.getcwd()
11+
sys.path.append(os.path.join(execpath,'gitpython\lib'))
12+
13+
importunittest
14+
importtempfile
15+
importshutil
16+
importzipfile
17+
18+
fromtest.testlibimport*
19+
fromgitimport*
20+
21+
classtest_Submodule(unittest.TestCase):
22+
23+
defsetUp(self):
24+
_p=tempfile.mkdtemp()
25+
demo_repos_file=fixture_path('sample_tree_of_repos_v1.zip')
26+
zipfile.ZipFile(demo_repos_file).extractall(_p)
27+
self.base_path=os.path.join(_p,'reposbase')
28+
29+
deftearDown(self):
30+
shutil.rmtree(self.base_path,True)
31+
32+
defdtest_01_browser_methods(self):
33+
_m=self._rpc_tree['browser.listdir']
34+
self.assertEquals(
35+
_m(''),
36+
{'path':'/','dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]}
37+
)
38+
self.assertEquals(
39+
_m('/'),
40+
{'path':'/','dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]}
41+
)
42+
self.assertEquals(
43+
_m('\\'),
44+
{'path':'/','dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]}
45+
)
46+
# crossing fingers and hoping the order is same on all platforms.
47+
self.assertEquals(
48+
_m('projects'),
49+
{'path':'/projects','dirs':[
50+
{'name':'common_files'},
51+
{'name':'demorepoone','is_git_dir':True},
52+
{'name':'projectone','is_git_dir':True}
53+
]}
54+
)
55+
self.assertEquals(
56+
_m('projects/common_files'),
57+
{'path':'/projects/common_files','dirs':[]}
58+
)
59+
# we don't allow seeing files / folders inside repo folders
60+
self.assertRaises(grm.PathUnfitError,_m,'projects/demorepoone')
61+
self.assertRaises(grm.PathUnfitError,_m,'projects/demorepoone/objects')
62+
# on top of fobiden, it also does not exist.
63+
self.assertRaises(grm.PathUnfitError,_m,'projects/demorepoone/kjhgjg')
64+
# all these should not exist
65+
self.assertRaises(grm.PathUnfitError,_m,'projects/blah')
66+
self.assertRaises(grm.PathUnfitError,_m,'/blah')
67+
# we should forbid seeing contents of folders above base path.
68+
self.assertRaises(grm.PathUnfitError,_m,'projects/../../../blah')
69+
70+
if__name__=="__main__":
71+
unittest.TextTestRunner(verbosity=2).run(
72+
unittest.TestSuite([
73+
unittest.TestLoader().loadTestsFromTestCase(test_Submodule),
74+
])
75+
)

‎test/git/test_tree.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ def test_content_from_string_tree_should_return_commit(self):
4848
text=fixture('ls_tree_commit').split("\n")[1]
4949

5050
tree=Tree.content_from_string(None,text)
51-
assert_none(tree)
51+
52+
assert_equal(Submodule,tree.__class__)
53+
assert_equal("d35b34c6e931b9da8f6941007a92c9c9a9b0141a",tree.id)
54+
# assert_equal("100644", tree.mode) # mode of submodule is irrelevant.
55+
assert_equal("bar",tree.name)
5256

5357
@raises(TypeError)
5458
deftest_content_from_string_invalid_type_should_raise(self):

‎test_submodule.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# test_submodule.py
2+
# Copyright (C) 2008-2010 Michael Trier (mtrier@gmail.com) and contributors
3+
#
4+
# This module is part of GitPython and is released under
5+
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
6+
7+
importos.path
8+
importsys
9+
10+
execpath=os.getcwd()
11+
sys.path.append(os.path.join(execpath,'gitpython\lib'))
12+
13+
importunittest
14+
importtempfile
15+
importshutil
16+
importzipfile
17+
18+
fromtest.testlibimport*
19+
fromgitimport*
20+
21+
classtest_Submodule(unittest.TestCase):
22+
23+
defsetUp(self):
24+
_p=tempfile.mkdtemp()
25+
demo_repos_file=fixture_path('sample_tree_of_repos_v1.zip')
26+
zipfile.ZipFile(demo_repos_file).extractall(_p)
27+
self.base_path=os.path.join(_p,'reposbase')
28+
29+
deftearDown(self):
30+
shutil.rmtree(self.base_path,True)
31+
32+
defdtest_01_browser_methods(self):
33+
_m=self._rpc_tree['browser.listdir']
34+
self.assertEquals(
35+
_m(''),
36+
{'path':'/','dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]}
37+
)
38+
self.assertEquals(
39+
_m('/'),
40+
{'path':'/','dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]}
41+
)
42+
self.assertEquals(
43+
_m('\\'),
44+
{'path':'/','dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]}
45+
)
46+
# crossing fingers and hoping the order is same on all platforms.
47+
self.assertEquals(
48+
_m('projects'),
49+
{'path':'/projects','dirs':[
50+
{'name':'common_files'},
51+
{'name':'demorepoone','is_git_dir':True},
52+
{'name':'projectone','is_git_dir':True}
53+
]}
54+
)
55+
self.assertEquals(
56+
_m('projects/common_files'),
57+
{'path':'/projects/common_files','dirs':[]}
58+
)
59+
# we don't allow seeing files / folders inside repo folders
60+
self.assertRaises(grm.PathUnfitError,_m,'projects/demorepoone')
61+
self.assertRaises(grm.PathUnfitError,_m,'projects/demorepoone/objects')
62+
# on top of fobiden, it also does not exist.
63+
self.assertRaises(grm.PathUnfitError,_m,'projects/demorepoone/kjhgjg')
64+
# all these should not exist
65+
self.assertRaises(grm.PathUnfitError,_m,'projects/blah')
66+
self.assertRaises(grm.PathUnfitError,_m,'/blah')
67+
# we should forbid seeing contents of folders above base path.
68+
self.assertRaises(grm.PathUnfitError,_m,'projects/../../../blah')
69+
70+
if__name__=="__main__":
71+
unittest.TextTestRunner(verbosity=2).run(
72+
unittest.TestSuite([
73+
unittest.TestLoader().loadTestsFromTestCase(test_Submodule),
74+
])
75+
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp