@@ -331,6 +331,8 @@ mod tests {
331331 use std:: time:: Duration ;
332332
333333 use crossbeam_channel:: unbounded;
334+ use serial_test:: serial;
335+ use tempfile:: TempDir ;
334336
335337 use crate :: sync:: tests:: { debug_cmd_print, repo_init} ;
336338 use crate :: sync:: RepoPath ;
@@ -368,4 +370,37 @@ mod tests {
368370
369371 assert ! ( result. is_ok( ) ) ;
370372 }
373+
374+ #[ test]
375+ #[ serial]
376+ fn test_env_variables ( ) {
377+ let ( _td, repo) = repo_init ( ) . unwrap ( ) ;
378+ let git_dir = repo. path ( ) ;
379+
380+ let ( tx_git, _rx_git) = unbounded ( ) ;
381+
382+ let empty_dir = TempDir :: new ( ) . unwrap ( ) ;
383+ let empty_path: RepoPath =
384+ empty_dir. path ( ) . to_str ( ) . unwrap ( ) . into ( ) ;
385+
386+ let arc_current = Arc :: new ( Mutex :: new ( AsyncLogResult {
387+ commits : Vec :: new ( ) ,
388+ duration : Duration :: default ( ) ,
389+ } ) ) ;
390+ let arc_background = Arc :: new ( AtomicBool :: new ( false ) ) ;
391+
392+ std:: env:: set_var ( "GIT_DIR" , git_dir) ;
393+
394+ let result = AsyncLog :: fetch_helper_without_filter (
395+ // We pass an empty path, thus testing whether `GIT_DIR`, set above, is taken into account.
396+ & empty_path,
397+ & arc_current,
398+ & arc_background,
399+ & tx_git,
400+ ) ;
401+
402+ std:: env:: remove_var ( "GIT_DIR" ) ;
403+
404+ assert ! ( result. is_ok( ) ) ;
405+ }
371406}
0 commit comments