From 61dbe884a2b11a53b7a6c774da2560c1c776c4de Mon Sep 17 00:00:00 2001 From: "D.Dotsenko" Date: Fri, 29 Oct 2010 22:07:48 -0700 Subject: Fixing recursion issue introduced with submodule support --- lib/git/submodule.py | 2 +- lib/git/tree.py | 2 +- test/fixtures/sample_tree_of_repos_v1.zip | Bin 0 -> 25260 bytes test/git/.directory | 3 ++ test/git/test_submodule.py | 75 ++++++++++++++++++++++++++++++ test/git/test_tree.py | 6 ++- test_submodule.py | 75 ++++++++++++++++++++++++++++++ 7 files changed, 160 insertions(+), 3 deletions(-) create mode 100755 test/fixtures/sample_tree_of_repos_v1.zip create mode 100644 test/git/.directory create mode 100755 test/git/test_submodule.py create mode 100644 test_submodule.py diff --git a/lib/git/submodule.py b/lib/git/submodule.py index c6c506f4..c878256d 100755 --- a/lib/git/submodule.py +++ b/lib/git/submodule.py @@ -29,7 +29,7 @@ class Submodule(object): """ def __init__(self, repo=None, id=None, mode=None, name='', - commit_context=None, path=''): + commit_context='', path=''): """ Initialize a newly instanced Submodule diff --git a/lib/git/tree.py b/lib/git/tree.py index 45f5fdcb..32f84052 100644 --- a/lib/git/tree.py +++ b/lib/git/tree.py @@ -10,7 +10,7 @@ import blob import submodule class Tree(LazyMixin): - def __init__(self, repo, id, mode=None, name=None, commit_context = None, path = ''): + def __init__(self, repo, id, mode=None, name=None, commit_context = '', path = ''): LazyMixin.__init__(self) self.repo = repo self.id = id diff --git a/test/fixtures/sample_tree_of_repos_v1.zip b/test/fixtures/sample_tree_of_repos_v1.zip new file mode 100755 index 00000000..9e86a07a Binary files /dev/null and b/test/fixtures/sample_tree_of_repos_v1.zip differ diff --git a/test/git/.directory b/test/git/.directory new file mode 100644 index 00000000..b4ada076 --- /dev/null +++ b/test/git/.directory @@ -0,0 +1,3 @@ +[Dolphin] +Timestamp=2010,10,28,0,8,28 +ViewMode=1 diff --git a/test/git/test_submodule.py b/test/git/test_submodule.py new file mode 100755 index 00000000..11f336a4 --- /dev/null +++ b/test/git/test_submodule.py @@ -0,0 +1,75 @@ +# test_submodule.py +# Copyright (C) 2008-2010 Michael Trier (mtrier@gmail.com) and contributors +# +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php + +import os.path +import sys + +execpath = os.getcwd() +sys.path.append(os.path.join(execpath, 'gitpython\lib')) + +import unittest +import tempfile +import shutil +import zipfile + +from test.testlib import * +from git import * + +class test_Submodule(unittest.TestCase): + + def setUp(self): + _p = tempfile.mkdtemp() + demo_repos_file = fixture_path('sample_tree_of_repos_v1.zip') + zipfile.ZipFile(demo_repos_file).extractall(_p) + self.base_path = os.path.join(_p, 'reposbase') + + def tearDown(self): + shutil.rmtree(self.base_path, True) + + def dtest_01_browser_methods(self): + _m = self._rpc_tree['browser.listdir'] + self.assertEquals( + _m(''), + {'path':'/', 'dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]} + ) + self.assertEquals( + _m('/'), + {'path':'/', 'dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]} + ) + self.assertEquals( + _m('\\'), + {'path':'/', 'dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]} + ) + # crossing fingers and hoping the order is same on all platforms. + self.assertEquals( + _m('projects'), + {'path':'/projects', 'dirs':[ + {'name':'common_files'}, + {'name':'demorepoone','is_git_dir':True}, + {'name':'projectone','is_git_dir':True} + ]} + ) + self.assertEquals( + _m('projects/common_files'), + {'path':'/projects/common_files', 'dirs':[]} + ) + # we don't allow seeing files / folders inside repo folders + self.assertRaises(grm.PathUnfitError, _m, 'projects/demorepoone') + self.assertRaises(grm.PathUnfitError, _m, 'projects/demorepoone/objects') + # on top of fobiden, it also does not exist. + self.assertRaises(grm.PathUnfitError, _m, 'projects/demorepoone/kjhgjg') + # all these should not exist + self.assertRaises(grm.PathUnfitError, _m, 'projects/blah') + self.assertRaises(grm.PathUnfitError, _m, '/blah') + # we should forbid seeing contents of folders above base path. + self.assertRaises(grm.PathUnfitError, _m, 'projects/../../../blah') + +if __name__ == "__main__": + unittest.TextTestRunner(verbosity=2).run( + unittest.TestSuite([ + unittest.TestLoader().loadTestsFromTestCase(test_Submodule), + ]) + ) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index 0ab6b9bc..6d6a72c6 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -48,7 +48,11 @@ class TestTree(object): text = fixture('ls_tree_commit').split("\n")[1] tree = Tree.content_from_string(None, text) - assert_none(tree) + + assert_equal(Submodule, tree.__class__) + assert_equal("d35b34c6e931b9da8f6941007a92c9c9a9b0141a", tree.id) + # assert_equal("100644", tree.mode) # mode of submodule is irrelevant. + assert_equal("bar", tree.name) @raises(TypeError) def test_content_from_string_invalid_type_should_raise(self): diff --git a/test_submodule.py b/test_submodule.py new file mode 100644 index 00000000..11f336a4 --- /dev/null +++ b/test_submodule.py @@ -0,0 +1,75 @@ +# test_submodule.py +# Copyright (C) 2008-2010 Michael Trier (mtrier@gmail.com) and contributors +# +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php + +import os.path +import sys + +execpath = os.getcwd() +sys.path.append(os.path.join(execpath, 'gitpython\lib')) + +import unittest +import tempfile +import shutil +import zipfile + +from test.testlib import * +from git import * + +class test_Submodule(unittest.TestCase): + + def setUp(self): + _p = tempfile.mkdtemp() + demo_repos_file = fixture_path('sample_tree_of_repos_v1.zip') + zipfile.ZipFile(demo_repos_file).extractall(_p) + self.base_path = os.path.join(_p, 'reposbase') + + def tearDown(self): + shutil.rmtree(self.base_path, True) + + def dtest_01_browser_methods(self): + _m = self._rpc_tree['browser.listdir'] + self.assertEquals( + _m(''), + {'path':'/', 'dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]} + ) + self.assertEquals( + _m('/'), + {'path':'/', 'dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]} + ) + self.assertEquals( + _m('\\'), + {'path':'/', 'dirs':[{'name':'projects'},{'name':'teams'},{'name':'users'}]} + ) + # crossing fingers and hoping the order is same on all platforms. + self.assertEquals( + _m('projects'), + {'path':'/projects', 'dirs':[ + {'name':'common_files'}, + {'name':'demorepoone','is_git_dir':True}, + {'name':'projectone','is_git_dir':True} + ]} + ) + self.assertEquals( + _m('projects/common_files'), + {'path':'/projects/common_files', 'dirs':[]} + ) + # we don't allow seeing files / folders inside repo folders + self.assertRaises(grm.PathUnfitError, _m, 'projects/demorepoone') + self.assertRaises(grm.PathUnfitError, _m, 'projects/demorepoone/objects') + # on top of fobiden, it also does not exist. + self.assertRaises(grm.PathUnfitError, _m, 'projects/demorepoone/kjhgjg') + # all these should not exist + self.assertRaises(grm.PathUnfitError, _m, 'projects/blah') + self.assertRaises(grm.PathUnfitError, _m, '/blah') + # we should forbid seeing contents of folders above base path. + self.assertRaises(grm.PathUnfitError, _m, 'projects/../../../blah') + +if __name__ == "__main__": + unittest.TextTestRunner(verbosity=2).run( + unittest.TestSuite([ + unittest.TestLoader().loadTestsFromTestCase(test_Submodule), + ]) + ) -- cgit v1.2.1