@@ -6,10 +6,7 @@ use gix_config::file::{
6
6
includes:: conditional,
7
7
init:: { self } ,
8
8
} ;
9
- use gix_ref:: {
10
- transaction:: { Change , PreviousValue , RefEdit } ,
11
- FullName , Target ,
12
- } ;
9
+ use gix_ref:: FullName ;
13
10
use gix_testtools:: tempfile:: tempdir;
14
11
15
12
use crate :: file:: { cow_str, init:: from_paths:: includes:: conditional:: git_init} ;
@@ -24,7 +21,7 @@ fn literal_branch_names_match() -> Result {
24
21
branch_name : "refs/heads/literal-match" ,
25
22
expect : Value :: OverrideByInclude ,
26
23
} ,
27
- GitEnv :: new ( ) ?,
24
+ & mut GitEnv :: new ( ) ?,
28
25
) ?;
29
26
Ok ( ( ) )
30
27
}
@@ -37,7 +34,7 @@ fn full_ref_names_do_not_match() -> Result {
37
34
branch_name : "refs/heads/simple" ,
38
35
expect : Value :: Base ,
39
36
} ,
40
- GitEnv :: new ( ) ?,
37
+ & mut GitEnv :: new ( ) ?,
41
38
) ?;
42
39
Ok ( ( ) )
43
40
}
@@ -50,37 +47,37 @@ fn non_branches_never_match() -> Result {
50
47
branch_name : "refs/bisect/good" ,
51
48
expect : Value :: Base ,
52
49
} ,
53
- GitEnv :: new ( ) ?,
50
+ & mut GitEnv :: new ( ) ?,
54
51
) ?;
55
52
Ok ( ( ) )
56
53
}
57
54
58
55
#[ test]
59
56
fn patterns_ending_with_slash_match_subdirectories_recursively ( ) -> Result {
60
57
let mut env = GitEnv :: new ( ) ?;
61
- env = assert_section_value (
58
+ assert_section_value (
62
59
Options {
63
60
condition : "feature/b/" ,
64
61
branch_name : "refs/heads/feature/b/start" ,
65
62
expect : Value :: OverrideByInclude ,
66
63
} ,
67
- env,
64
+ & mut env,
68
65
) ?;
69
- env = assert_section_value (
66
+ assert_section_value (
70
67
Options {
71
68
condition : "feature/" ,
72
69
branch_name : "refs/heads/feature/b/start" ,
73
70
expect : Value :: OverrideByInclude ,
74
71
} ,
75
- env,
72
+ & mut env,
76
73
) ?;
77
74
assert_section_value_msg (
78
75
Options {
79
76
condition : "feature/b/start" ,
80
77
branch_name : "refs/heads/feature/b/start" ,
81
78
expect : Value :: OverrideByInclude ,
82
79
} ,
83
- env,
80
+ & mut env,
84
81
"just for good measure, we would expect branch paths to work as well" . into ( ) ,
85
82
) ?;
86
83
Ok ( ( ) )
@@ -89,46 +86,46 @@ fn patterns_ending_with_slash_match_subdirectories_recursively() -> Result {
89
86
#[ test]
90
87
fn simple_glob_patterns ( ) -> Result {
91
88
let mut env = GitEnv :: new ( ) ?;
92
- env = assert_section_value (
89
+ assert_section_value (
93
90
Options {
94
91
condition : "prefix*" ,
95
92
branch_name : "refs/heads/prefixsuffix" ,
96
93
expect : Value :: OverrideByInclude ,
97
94
} ,
98
- env,
95
+ & mut env,
99
96
) ?;
100
- env = assert_section_value_msg (
97
+ assert_section_value_msg (
101
98
Options {
102
99
condition : "prefix*" ,
103
100
branch_name : "refs/heads/prefix/suffix" ,
104
101
expect : Value :: Base ,
105
102
} ,
106
- env,
103
+ & mut env,
107
104
"single-stars do not cross component boundaries" . into ( ) ,
108
105
) ?;
109
- env = assert_section_value (
106
+ assert_section_value (
110
107
Options {
111
108
condition : "*suffix" ,
112
109
branch_name : "refs/heads/prefixsuffix" ,
113
110
expect : Value :: OverrideByInclude ,
114
111
} ,
115
- env,
112
+ & mut env,
116
113
) ?;
117
- env = assert_section_value (
114
+ assert_section_value (
118
115
Options {
119
116
condition : "*/suffix" ,
120
117
branch_name : "refs/heads/prefix/suffix" ,
121
118
expect : Value :: OverrideByInclude ,
122
119
} ,
123
- env,
120
+ & mut env,
124
121
) ?;
125
122
assert_section_value_msg (
126
123
Options {
127
124
condition : "*suffix" ,
128
125
branch_name : "refs/heads/prefix/suffix" ,
129
126
expect : Value :: Base ,
130
127
} ,
131
- env,
128
+ & mut env,
132
129
"single-stars do not cross component boundaries" . into ( ) ,
133
130
) ?;
134
131
Ok ( ( ) )
@@ -137,21 +134,21 @@ fn simple_glob_patterns() -> Result {
137
134
#[ test]
138
135
fn simple_globs_do_not_cross_component_boundary ( ) -> Result {
139
136
let mut env = GitEnv :: new ( ) ?;
140
- env = assert_section_value (
137
+ assert_section_value (
141
138
Options {
142
139
condition : "feature/*/start" ,
143
140
branch_name : "refs/heads/feature/a/start" ,
144
141
expect : Value :: OverrideByInclude ,
145
142
} ,
146
- env,
143
+ & mut env,
147
144
) ?;
148
145
assert_section_value_msg (
149
146
Options {
150
147
condition : "feature/*/start" ,
151
148
branch_name : "refs/heads/feature/a/b/start" ,
152
149
expect : Value :: Base ,
153
150
} ,
154
- env,
151
+ & mut env,
155
152
"path matching would never match 'a/b' as it cannot cross /" . into ( ) ,
156
153
) ?;
157
154
Ok ( ( ) )
@@ -165,7 +162,7 @@ fn double_star_globs_cross_component_boundaries() -> Result {
165
162
branch_name : "refs/heads/feature/a/b/start" ,
166
163
expect : Value :: OverrideByInclude ,
167
164
} ,
168
- GitEnv :: new ( ) ?,
165
+ & mut GitEnv :: new ( ) ?,
169
166
) ?;
170
167
Ok ( ( ) )
171
168
}
@@ -177,15 +174,14 @@ enum Value {
177
174
178
175
#[ derive( Debug ) ]
179
176
struct GitEnv {
180
- repo : gix:: Repository ,
181
177
dir : gix_testtools:: tempfile:: TempDir ,
182
178
}
183
179
184
180
impl GitEnv {
185
181
fn new ( ) -> crate :: Result < Self > {
186
182
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 } )
189
185
}
190
186
}
191
187
@@ -195,7 +191,7 @@ struct Options<'a> {
195
191
expect : Value ,
196
192
}
197
193
198
- fn assert_section_value ( opts : Options , env : GitEnv ) -> crate :: Result < GitEnv > {
194
+ fn assert_section_value ( opts : Options , env : & mut GitEnv ) -> crate :: Result {
199
195
assert_section_value_msg ( opts, env, None )
200
196
}
201
197
@@ -205,9 +201,9 @@ fn assert_section_value_msg(
205
201
branch_name,
206
202
expect,
207
203
} : Options ,
208
- GitEnv { repo , dir } : GitEnv ,
204
+ GitEnv { dir } : & mut GitEnv ,
209
205
message : Option < & str > ,
210
- ) -> crate :: Result < GitEnv > {
206
+ ) -> crate :: Result < ( ) > {
211
207
let root_config = dir. path ( ) . join ( "config" ) ;
212
208
let included_config = dir. path ( ) . join ( "include.config" ) ;
213
209
@@ -264,36 +260,23 @@ value = branch-override-by-include
264
260
"the base value is overridden by an included file because the condition matches" ,
265
261
} ,
266
262
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
+ }
268
270
) ;
269
271
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 ( ( ) )
289
275
}
290
276
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 {
295
278
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 ( ) )
297
280
. args ( [ "config" , "--get" , "section.value" ] )
298
281
. env ( "GIT_DIR" , git_dir)
299
282
. env ( "HOME" , git_dir)
@@ -302,11 +285,18 @@ fn assure_git_agrees(
302
285
. current_dir ( git_dir)
303
286
. output ( ) ?;
304
287
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
+ } ;
305
295
assert ! (
306
296
output. status. success( ) ,
307
297
"{:?}, {:?} for debugging" ,
308
298
output,
309
- dir . into_path ( )
299
+ keep_dir_on_disk ( )
310
300
) ;
311
301
let git_output: BString = output. stdout . trim_end ( ) . into ( ) ;
312
302
assert_eq ! (
@@ -316,7 +306,7 @@ fn assure_git_agrees(
316
306
Value :: OverrideByInclude => "branch-override-by-include" ,
317
307
} ,
318
308
"git disagrees with gix-config, {:?} for debugging" ,
319
- dir . into_path ( )
309
+ keep_dir_on_disk ( )
320
310
) ;
321
- Ok ( dir )
311
+ Ok ( ( ) )
322
312
}
0 commit comments