@@ -6,10 +6,7 @@ use gix_config::file::{
66    includes:: conditional, 
77    init:: { self } , 
88} ; 
9- use  gix_ref:: { 
10-     transaction:: { Change ,  PreviousValue ,  RefEdit } , 
11-     FullName ,  Target , 
12- } ; 
9+ use  gix_ref:: FullName ; 
1310use  gix_testtools:: tempfile:: tempdir; 
1411
1512use  crate :: file:: { cow_str,  init:: from_paths:: includes:: conditional:: git_init} ; 
@@ -24,7 +21,7 @@ fn literal_branch_names_match() -> Result {
2421            branch_name :  "refs/heads/literal-match" , 
2522            expect :  Value :: OverrideByInclude , 
2623        } , 
27-         GitEnv :: new ( ) ?, 
24+         & mut   GitEnv :: new ( ) ?, 
2825    ) ?; 
2926    Ok ( ( ) ) 
3027} 
@@ -37,7 +34,7 @@ fn full_ref_names_do_not_match() -> Result {
3734            branch_name :  "refs/heads/simple" , 
3835            expect :  Value :: Base , 
3936        } , 
40-         GitEnv :: new ( ) ?, 
37+         & mut   GitEnv :: new ( ) ?, 
4138    ) ?; 
4239    Ok ( ( ) ) 
4340} 
@@ -50,37 +47,37 @@ fn non_branches_never_match() -> Result {
5047            branch_name :  "refs/bisect/good" , 
5148            expect :  Value :: Base , 
5249        } , 
53-         GitEnv :: new ( ) ?, 
50+         & mut   GitEnv :: new ( ) ?, 
5451    ) ?; 
5552    Ok ( ( ) ) 
5653} 
5754
5855#[ test]  
5956fn  patterns_ending_with_slash_match_subdirectories_recursively ( )  -> Result  { 
6057    let  mut  env = GitEnv :: new ( ) ?; 
61-     env =  assert_section_value ( 
58+     assert_section_value ( 
6259        Options  { 
6360            condition :  "feature/b/" , 
6461            branch_name :  "refs/heads/feature/b/start" , 
6562            expect :  Value :: OverrideByInclude , 
6663        } , 
67-         env, 
64+         & mut   env, 
6865    ) ?; 
69-     env =  assert_section_value ( 
66+     assert_section_value ( 
7067        Options  { 
7168            condition :  "feature/" , 
7269            branch_name :  "refs/heads/feature/b/start" , 
7370            expect :  Value :: OverrideByInclude , 
7471        } , 
75-         env, 
72+         & mut   env, 
7673    ) ?; 
7774    assert_section_value_msg ( 
7875        Options  { 
7976            condition :  "feature/b/start" , 
8077            branch_name :  "refs/heads/feature/b/start" , 
8178            expect :  Value :: OverrideByInclude , 
8279        } , 
83-         env, 
80+         & mut   env, 
8481        "just for good measure, we would expect branch paths to work as well" . into ( ) , 
8582    ) ?; 
8683    Ok ( ( ) ) 
@@ -89,46 +86,46 @@ fn patterns_ending_with_slash_match_subdirectories_recursively() -> Result {
8986#[ test]  
9087fn  simple_glob_patterns ( )  -> Result  { 
9188    let  mut  env = GitEnv :: new ( ) ?; 
92-     env =  assert_section_value ( 
89+     assert_section_value ( 
9390        Options  { 
9491            condition :  "prefix*" , 
9592            branch_name :  "refs/heads/prefixsuffix" , 
9693            expect :  Value :: OverrideByInclude , 
9794        } , 
98-         env, 
95+         & mut   env, 
9996    ) ?; 
100-     env =  assert_section_value_msg ( 
97+     assert_section_value_msg ( 
10198        Options  { 
10299            condition :  "prefix*" , 
103100            branch_name :  "refs/heads/prefix/suffix" , 
104101            expect :  Value :: Base , 
105102        } , 
106-         env, 
103+         & mut   env, 
107104        "single-stars do not cross component boundaries" . into ( ) , 
108105    ) ?; 
109-     env =  assert_section_value ( 
106+     assert_section_value ( 
110107        Options  { 
111108            condition :  "*suffix" , 
112109            branch_name :  "refs/heads/prefixsuffix" , 
113110            expect :  Value :: OverrideByInclude , 
114111        } , 
115-         env, 
112+         & mut   env, 
116113    ) ?; 
117-     env =  assert_section_value ( 
114+     assert_section_value ( 
118115        Options  { 
119116            condition :  "*/suffix" , 
120117            branch_name :  "refs/heads/prefix/suffix" , 
121118            expect :  Value :: OverrideByInclude , 
122119        } , 
123-         env, 
120+         & mut   env, 
124121    ) ?; 
125122    assert_section_value_msg ( 
126123        Options  { 
127124            condition :  "*suffix" , 
128125            branch_name :  "refs/heads/prefix/suffix" , 
129126            expect :  Value :: Base , 
130127        } , 
131-         env, 
128+         & mut   env, 
132129        "single-stars do not cross component boundaries" . into ( ) , 
133130    ) ?; 
134131    Ok ( ( ) ) 
@@ -137,21 +134,21 @@ fn simple_glob_patterns() -> Result {
137134#[ test]  
138135fn  simple_globs_do_not_cross_component_boundary ( )  -> Result  { 
139136    let  mut  env = GitEnv :: new ( ) ?; 
140-     env =  assert_section_value ( 
137+     assert_section_value ( 
141138        Options  { 
142139            condition :  "feature/*/start" , 
143140            branch_name :  "refs/heads/feature/a/start" , 
144141            expect :  Value :: OverrideByInclude , 
145142        } , 
146-         env, 
143+         & mut   env, 
147144    ) ?; 
148145    assert_section_value_msg ( 
149146        Options  { 
150147            condition :  "feature/*/start" , 
151148            branch_name :  "refs/heads/feature/a/b/start" , 
152149            expect :  Value :: Base , 
153150        } , 
154-         env, 
151+         & mut   env, 
155152        "path matching would never match 'a/b' as it cannot cross /" . into ( ) , 
156153    ) ?; 
157154    Ok ( ( ) ) 
@@ -165,7 +162,7 @@ fn double_star_globs_cross_component_boundaries() -> Result {
165162            branch_name :  "refs/heads/feature/a/b/start" , 
166163            expect :  Value :: OverrideByInclude , 
167164        } , 
168-         GitEnv :: new ( ) ?, 
165+         & mut   GitEnv :: new ( ) ?, 
169166    ) ?; 
170167    Ok ( ( ) ) 
171168} 
@@ -177,15 +174,14 @@ enum Value {
177174
178175#[ derive( Debug ) ]  
179176struct  GitEnv  { 
180-     repo :  gix:: Repository , 
181177    dir :  gix_testtools:: tempfile:: TempDir , 
182178} 
183179
184180impl  GitEnv  { 
185181    fn  new ( )  -> crate :: Result < Self >  { 
186182        let  dir = tempdir ( ) ?; 
187-         let  repo =  git_init ( dir. path ( ) ,  true ) ?; 
188-         Ok ( GitEnv  {  repo ,   dir } ) 
183+         git_init ( dir. path ( ) ,  true ) ?; 
184+         Ok ( GitEnv  {  dir } ) 
189185    } 
190186} 
191187
@@ -195,7 +191,7 @@ struct Options<'a> {
195191    expect :  Value , 
196192} 
197193
198- fn  assert_section_value ( opts :  Options ,  env :  GitEnv )  -> crate :: Result < GitEnv >  { 
194+ fn  assert_section_value ( opts :  Options ,  env :  & mut   GitEnv )  -> crate :: Result  { 
199195    assert_section_value_msg ( opts,  env,  None ) 
200196} 
201197
@@ -205,9 +201,9 @@ fn assert_section_value_msg(
205201        branch_name, 
206202        expect, 
207203    } :  Options , 
208-     GitEnv  {  repo ,   dir } :  GitEnv , 
204+     GitEnv  {  dir } :   & mut  GitEnv , 
209205    message :  Option < & str > , 
210- )  -> crate :: Result < GitEnv >  { 
206+ )  -> crate :: Result < ( ) >  { 
211207    let  root_config = dir. path ( ) . join ( "config" ) ; 
212208    let  included_config = dir. path ( ) . join ( "include.config" ) ; 
213209
@@ -264,36 +260,23 @@ value = branch-override-by-include
264260                "the base value is overridden by an included file because the condition matches" , 
265261        } , 
266262        message, 
267-         dir. into_path( ) 
263+         { 
264+             let  dir = std:: mem:: replace( 
265+                 dir, 
266+                 gix_testtools:: tempfile:: TempDir :: new( ) . expect( "substitute can be created" ) , 
267+             ) ; 
268+             dir. into_path( ) 
269+         } 
268270    ) ; 
269271
270-     repo. refs 
271-         . transaction ( ) 
272-         . prepare ( 
273-             Some ( RefEdit  { 
274-                 name :  "HEAD" . try_into ( ) ?, 
275-                 change :  Change :: Update  { 
276-                     log :  Default :: default ( ) , 
277-                     expected :  PreviousValue :: Any , 
278-                     new :  Target :: Symbolic ( branch_name) , 
279-                 } , 
280-                 deref :  false , 
281-             } ) , 
282-             gix:: lock:: acquire:: Fail :: Immediately , 
283-             gix:: lock:: acquire:: Fail :: Immediately , 
284-         ) ?
285-         . commit ( repo. committer ( ) . transpose ( ) ?) ?; 
286- 
287-     let  dir = assure_git_agrees ( expect,  dir) ?; 
288-     Ok ( GitEnv  {  repo,  dir } ) 
272+     std:: fs:: write ( dir. path ( ) . join ( "HEAD" ) ,  format ! ( "ref: {}" ,  branch_name. as_bstr( ) ) ) ?; 
273+     assure_git_agrees ( expect,  dir) ?; 
274+     Ok ( ( ) ) 
289275} 
290276
291- fn  assure_git_agrees ( 
292-     expected :  Value , 
293-     dir :  gix_testtools:: tempfile:: TempDir , 
294- )  -> crate :: Result < gix_testtools:: tempfile:: TempDir >  { 
277+ fn  assure_git_agrees ( expected :  Value ,  dir :  & mut  gix_testtools:: tempfile:: TempDir )  -> crate :: Result  { 
295278    let  git_dir = dir. path ( ) ; 
296-     let  output = std:: process:: Command :: new ( "git" ) 
279+     let  output = std:: process:: Command :: new ( gix_path :: env :: exe_invocation ( ) ) 
297280        . args ( [ "config" ,  "--get" ,  "section.value" ] ) 
298281        . env ( "GIT_DIR" ,  git_dir) 
299282        . env ( "HOME" ,  git_dir) 
@@ -302,11 +285,18 @@ fn assure_git_agrees(
302285        . current_dir ( git_dir) 
303286        . output ( ) ?; 
304287
288+     let  mut  keep_dir_on_disk = || { 
289+         let  dir = std:: mem:: replace ( 
290+             dir, 
291+             gix_testtools:: tempfile:: TempDir :: new ( ) . expect ( "substitute can be created" ) , 
292+         ) ; 
293+         dir. into_path ( ) 
294+     } ; 
305295    assert ! ( 
306296        output. status. success( ) , 
307297        "{:?}, {:?} for debugging" , 
308298        output, 
309-         dir . into_path ( ) 
299+         keep_dir_on_disk ( ) 
310300    ) ; 
311301    let  git_output:  BString  = output. stdout . trim_end ( ) . into ( ) ; 
312302    assert_eq ! ( 
@@ -316,7 +306,7 @@ fn assure_git_agrees(
316306            Value :: OverrideByInclude  => "branch-override-by-include" , 
317307        } , 
318308        "git disagrees with gix-config, {:?} for debugging" , 
319-         dir . into_path ( ) 
309+         keep_dir_on_disk ( ) 
320310    ) ; 
321-     Ok ( dir ) 
311+     Ok ( ( ) ) 
322312} 
0 commit comments