14
14
15
15
GIT_REPO = os .path .dirname (os .path .dirname (os .path .dirname (__file__ )))
16
16
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
+
17
22
#{ Routines
18
23
19
24
def fixture_path (name ):
@@ -58,41 +63,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info):
58
63
os .chmod (fullpath , 0777 )
59
64
os .remove (fullpath )
60
65
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 ):
96
67
"""
97
68
Same as with_bare_repo, but clones the rorepo as non-bare repository, checking
98
69
out the working tree at the given working_tree_ref.
@@ -105,11 +76,17 @@ def with_rw_repo(working_tree_ref):
105
76
assert isinstance (working_tree_ref , basestring ), "Decorator requires ref name for working tree checkout"
106
77
def argument_passer (func ):
107
78
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 )
110
85
111
86
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
113
90
114
91
prev_cwd = os .getcwd ()
115
92
os .chdir (rw_repo .working_dir )
0 commit comments