@@ -123,6 +123,7 @@ where
123
123
mod tests {
124
124
125
125
use super :: * ;
126
+ use crate :: tests:: repo_utils;
126
127
127
128
fn empty_slog ( ) -> slog:: Logger {
128
129
slog:: Logger :: root ( slog:: Discard , o ! ( ) )
@@ -141,46 +142,6 @@ mod tests {
141
142
( dir, repo)
142
143
}
143
144
144
- fn empty_commit < ' repo > (
145
- repo : & ' repo git2:: Repository ,
146
- update_ref : & str ,
147
- message : & str ,
148
- parents : & [ & git2:: Commit ] ,
149
- ) -> git2:: Commit < ' repo > {
150
- let sig = repo. signature ( ) . unwrap ( ) ;
151
- let tree = repo
152
- . find_tree ( repo. treebuilder ( None ) . unwrap ( ) . write ( ) . unwrap ( ) )
153
- . unwrap ( ) ;
154
-
155
- repo. find_commit (
156
- repo. commit ( Some ( update_ref) , & sig, & sig, message, & tree, parents)
157
- . unwrap ( ) ,
158
- )
159
- . unwrap ( )
160
- }
161
-
162
- fn empty_commit_chain < ' repo > (
163
- repo : & ' repo git2:: Repository ,
164
- update_ref : & str ,
165
- initial_parents : & [ & git2:: Commit ] ,
166
- length : usize ,
167
- ) -> Vec < git2:: Commit < ' repo > > {
168
- let mut ret = Vec :: with_capacity ( length) ;
169
-
170
- for idx in 0 ..length {
171
- let next = if let Some ( last) = ret. last ( ) {
172
- // TODO: how to deduplicate the rest of this call if last doesn't live long enough?
173
- empty_commit ( repo, update_ref, & idx. to_string ( ) , & [ last] )
174
- } else {
175
- empty_commit ( repo, update_ref, & idx. to_string ( ) , initial_parents)
176
- } ;
177
- ret. push ( next)
178
- }
179
-
180
- assert_eq ! ( ret. len( ) , length) ;
181
- ret
182
- }
183
-
184
145
fn assert_stack_matches_chain ( length : usize , stack : & [ git2:: Commit ] , chain : & [ git2:: Commit ] ) {
185
146
assert_eq ! ( stack. len( ) , length) ;
186
147
for ( chain_commit, stack_commit) in chain. iter ( ) . rev ( ) . take ( length) . zip ( stack) {
@@ -191,7 +152,7 @@ mod tests {
191
152
#[ test]
192
153
fn test_stack_hides_other_branches ( ) {
193
154
let ( _dir, repo) = init_repo ( ) ;
194
- let commits = empty_commit_chain ( & repo, "HEAD" , & [ ] , 2 ) ;
155
+ let commits = repo_utils :: empty_commit_chain ( & repo, "HEAD" , & [ ] , 2 ) ;
195
156
repo. branch ( "hide" , & commits[ 0 ] , false ) . unwrap ( ) ;
196
157
197
158
assert_stack_matches_chain (
@@ -204,7 +165,7 @@ mod tests {
204
165
#[ test]
205
166
fn test_stack_uses_custom_base ( ) {
206
167
let ( _dir, repo) = init_repo ( ) ;
207
- let commits = empty_commit_chain ( & repo, "HEAD" , & [ ] , 3 ) ;
168
+ let commits = repo_utils :: empty_commit_chain ( & repo, "HEAD" , & [ ] , 3 ) ;
208
169
repo. branch ( "hide" , & commits[ 1 ] , false ) . unwrap ( ) ;
209
170
210
171
assert_stack_matches_chain (
@@ -224,7 +185,7 @@ mod tests {
224
185
#[ test]
225
186
fn test_stack_stops_at_configured_limit ( ) {
226
187
let ( _dir, repo) = init_repo ( ) ;
227
- let commits = empty_commit_chain ( & repo, "HEAD" , & [ ] , config:: MAX_STACK + 2 ) ;
188
+ let commits = repo_utils :: empty_commit_chain ( & repo, "HEAD" , & [ ] , config:: MAX_STACK + 2 ) ;
228
189
repo. config ( )
229
190
. unwrap ( )
230
191
. set_i64 (
@@ -243,12 +204,13 @@ mod tests {
243
204
#[ test]
244
205
fn test_stack_stops_at_foreign_author ( ) {
245
206
let ( _dir, repo) = init_repo ( ) ;
246
- let old_commits = empty_commit_chain ( & repo, "HEAD" , & [ ] , 3 ) ;
207
+ let old_commits = repo_utils :: empty_commit_chain ( & repo, "HEAD" , & [ ] , 3 ) ;
247
208
repo. config ( )
248
209
. unwrap ( )
249
210
. set_str ( "user.name" , "nobody2" )
250
211
. unwrap ( ) ;
251
- let new_commits = empty_commit_chain ( & repo, "HEAD" , & [ old_commits. last ( ) . unwrap ( ) ] , 2 ) ;
212
+ let new_commits =
213
+ repo_utils:: empty_commit_chain ( & repo, "HEAD" , & [ old_commits. last ( ) . unwrap ( ) ] , 2 ) ;
252
214
253
215
assert_stack_matches_chain (
254
216
2 ,
@@ -260,13 +222,8 @@ mod tests {
260
222
#[ test]
261
223
fn test_stack_stops_at_merges ( ) {
262
224
let ( _dir, repo) = init_repo ( ) ;
263
- let first = empty_commit ( & repo, "HEAD" , "first" , & [ ] ) ;
264
- // equivalent to checkout --orphan
265
- repo. set_head ( "refs/heads/new" ) . unwrap ( ) ;
266
- let second = empty_commit ( & repo, "HEAD" , "second" , & [ ] ) ;
267
- // the current commit must be the first parent
268
- let merge = empty_commit ( & repo, "HEAD" , "merge" , & [ & second, & first] ) ;
269
- let commits = empty_commit_chain ( & repo, "HEAD" , & [ & merge] , 2 ) ;
225
+ let merge = repo_utils:: merge_commit ( & repo, & [ ] ) ;
226
+ let commits = repo_utils:: empty_commit_chain ( & repo, "HEAD" , & [ & merge] , 2 ) ;
270
227
271
228
assert_stack_matches_chain (
272
229
2 ,
0 commit comments