Skip to content

Commit 61dbe88

Browse files
committed
Fixing recursion issue introduced with submodule support
1 parent cfd2121 commit 61dbe88

File tree

7 files changed

+160
-3
lines changed

7 files changed

+160
-3
lines changed

lib/git/submodule.py

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import submodule
1111

1212
class Tree(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

+3
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

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# test_submodule.py
2+
# Copyright (C) 2008-2010 Michael Trier ([email protected]) 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+
import os.path
8+
import sys
9+
10+
execpath = os.getcwd()
11+
sys.path.append(os.path.join(execpath, 'gitpython\lib'))
12+
13+
import unittest
14+
import tempfile
15+
import shutil
16+
import zipfile
17+
18+
from test.testlib import *
19+
from git import *
20+
21+
class test_Submodule(unittest.TestCase):
22+
23+
def setUp(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+
def tearDown(self):
30+
shutil.rmtree(self.base_path, True)
31+
32+
def dtest_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

+5-1
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
def test_content_from_string_invalid_type_should_raise(self):

test_submodule.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# test_submodule.py
2+
# Copyright (C) 2008-2010 Michael Trier ([email protected]) 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+
import os.path
8+
import sys
9+
10+
execpath = os.getcwd()
11+
sys.path.append(os.path.join(execpath, 'gitpython\lib'))
12+
13+
import unittest
14+
import tempfile
15+
import shutil
16+
import zipfile
17+
18+
from test.testlib import *
19+
from git import *
20+
21+
class test_Submodule(unittest.TestCase):
22+
23+
def setUp(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+
def tearDown(self):
30+
shutil.rmtree(self.base_path, True)
31+
32+
def dtest_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)