@@ -9,7 +9,16 @@ use walkdir::WalkDir;
9
9
10
10
const GITRS_ROOT_DEFAULT : & str = "src" ;
11
11
12
- pub fn sync ( root : PathBuf , repos : & HashMap < String , repo:: Repo > , _clean_only : & bool ) -> Result < ( ) > {
12
+ pub fn sync ( root : PathBuf , repos : & HashMap < String , repo:: Repo > , clean_only : & bool ) -> Result < ( ) > {
13
+ sync_with_fn ( root, repos, clean_only, clone_ssh)
14
+ }
15
+
16
+ fn sync_with_fn (
17
+ root : PathBuf ,
18
+ repos : & HashMap < String , repo:: Repo > ,
19
+ _clean_only : & bool ,
20
+ clone_fn : fn ( & str , & Path ) -> Result < ( ) > ,
21
+ ) -> Result < ( ) > {
13
22
for entry in WalkDir :: new ( root. as_path ( ) )
14
23
. min_depth ( 3 ) // forces it to look at full paths only
15
24
. max_depth ( 3 )
@@ -38,7 +47,7 @@ pub fn sync(root: PathBuf, repos: &HashMap<String, repo::Repo>, _clean_only: &bo
38
47
debug ! ( "On repository: {:?}" , r. get_name( ) ) ;
39
48
40
49
if !root. join ( r. get_name ( ) ) . exists ( ) {
41
- clone_ssh ( r. get_url ( ) , root. join ( r. get_name ( ) ) . as_path ( ) ) ?;
50
+ clone_fn ( r. get_url ( ) , root. join ( r. get_name ( ) ) . as_path ( ) ) ?;
42
51
}
43
52
}
44
53
@@ -116,6 +125,7 @@ fn root(p: Option<PathBuf>) -> PathBuf {
116
125
#[ cfg( test) ]
117
126
mod tests {
118
127
use super :: * ;
128
+ use repo;
119
129
use tempfile:: { tempdir, TempDir } ;
120
130
extern crate log;
121
131
use env_logger;
@@ -171,4 +181,49 @@ mod tests {
171
181
env:: set_var ( "HOME" , old_home) ;
172
182
cleanup ( root) ;
173
183
}
184
+
185
+ #[ test]
186
+ fn test_sync_add_repo_dir_doesnt_exists ( ) {
187
+ let root = setup ( ) ;
188
+
189
+ let got = sync (
190
+ root. path ( ) . to_path_buf ( ) ,
191
+ & HashMap :: from ( [ (
192
+ "github.com/a/a" . to_string ( ) ,
193
+ repo:: Repo :: new ( )
194
+ . name ( "github.com/a/a" . to_string ( ) )
195
+ . expect ( "sync name failed" )
196
+ . url ( "github.com/a/a" . to_string ( ) )
197
+ . expect ( "sync url failed" )
198
+ . pin ( false )
199
+ . sha ( "" . to_string ( ) )
200
+ . to_owned ( ) ,
201
+ ) ] ) ,
202
+ & false ,
203
+ ) ;
204
+ assert_eq ! ( got. is_err( ) , false ) ;
205
+
206
+ cleanup ( root) ;
207
+ }
208
+
209
+ #[ test]
210
+ fn test_sync_add_repo_dir_exists ( ) {
211
+ let root = setup ( ) ;
212
+ cleanup ( root) ;
213
+ unimplemented ! ( "test_sync" ) ;
214
+ }
215
+
216
+ #[ test]
217
+ fn test_sync_remove_repo_dir_exists ( ) {
218
+ let root = setup ( ) ;
219
+ cleanup ( root) ;
220
+ unimplemented ! ( "test_sync" ) ;
221
+ }
222
+
223
+ #[ test]
224
+ fn test_sync_remove_repo_dir_doesnt_exists ( ) {
225
+ let root = setup ( ) ;
226
+ cleanup ( root) ;
227
+ unimplemented ! ( "test_sync" ) ;
228
+ }
174
229
}
0 commit comments