1414
1515GIT_REPO = os .path .dirname (os .path .dirname (os .path .dirname (__file__ )))
1616
17+ __all__ = (
18+ 'fixture_path' , 'fixture' , 'absolute_project_path' , 'StringProcessAdapter' ,
19+ 'with_rw_repo' , 'with_rw_and_rw_remote_repo' , 'TestBase' , 'TestCase' , 'GIT_REPO'
20+ )
21+
1722#{ Routines
1823
1924def fixture_path (name ):
@@ -58,41 +63,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info):
5863 os .chmod (fullpath , 0777 )
5964 os .remove (fullpath )
6065
61- def with_bare_rw_repo (func ):
62- """
63- Decorator providing a specially made read-write repository to the test case
64- decorated with it. The test case requires the following signature::
65- def case(self, rw_repo)
66-
67- The rwrepo will be a bare clone or the types rorepo. Once the method finishes,
68- it will be removed completely.
69-
70- Use this if you want to make purely index based adjustments, change refs, create
71- heads, generally operations that do not need a working tree."""
72- def bare_repo_creator (self ):
73- repo_dir = tempfile .mktemp ("bare_repo_%s" % func .__name__ )
74- rw_repo = self .rorepo .clone (repo_dir , shared = True , bare = True )
75- prev_cwd = os .getcwd ()
76- try :
77- try :
78- return func (self , rw_repo )
79- except :
80- # assure we keep the repo for debugging
81- print >> sys .stderr , "Keeping bare repo after failure: %s" % repo_dir
82- repo_dir = None
83- raise
84- # END handle exceptions
85- finally :
86- rw_repo .git .clear_cache ()
87- if repo_dir is not None :
88- shutil .rmtree (repo_dir , onerror = _rmtree_onerror )
89- # END remove repo dir
90- # END cleanup
91- # END bare repo creator
92- bare_repo_creator .__name__ = func .__name__
93- return bare_repo_creator
94-
95- def with_rw_repo (working_tree_ref ):
66+ def with_rw_repo (working_tree_ref , bare = False ):
9667 """
9768 Same as with_bare_repo, but clones the rorepo as non-bare repository, checking
9869 out the working tree at the given working_tree_ref.
@@ -105,11 +76,17 @@ def with_rw_repo(working_tree_ref):
10576 assert isinstance (working_tree_ref , basestring ), "Decorator requires ref name for working tree checkout"
10677 def argument_passer (func ):
10778 def repo_creator (self ):
108- repo_dir = tempfile .mktemp ("non_bare_%s" % func .__name__ )
109- rw_repo = self .rorepo .clone (repo_dir , shared = True , bare = False , n = True )
79+ prefix = 'non_'
80+ if bare :
81+ prefix = ''
82+ #END handle prefix
83+ repo_dir = tempfile .mktemp ("%sbare_%s" % (prefix , func .__name__ ))
84+ rw_repo = self .rorepo .clone (repo_dir , shared = True , bare = bare , n = True )
11085
11186 rw_repo .head .commit = rw_repo .commit (working_tree_ref )
112- rw_repo .head .reference .checkout ()
87+ if not bare :
88+ rw_repo .head .reference .checkout ()
89+ # END handle checkout
11390
11491 prev_cwd = os .getcwd ()
11592 os .chdir (rw_repo .working_dir )
0 commit comments