@@ -442,3 +442,34 @@ def setup_standard_yadm_dir(paths):
442442    std_yadm_data .join ("repo.git" ).mksymlinkto (paths .repo , absolute = 1 )
443443    std_yadm_dir .join ("encrypt" ).mksymlinkto (paths .encrypt , absolute = 1 )
444444    return  std_yadm_dir , std_yadm_data 
445+ 
446+ 
447+ @pytest .mark .usefixtures ("ds1_copy" ) 
448+ def  test_alt_preserves_user_symlink_when_no_alt_tracked (runner , paths ):
449+     """Issue #236: User symlinks preserved when no yadm alternate is tracked.""" 
450+     yadm_dir , yadm_data  =  setup_standard_yadm_dir (paths )
451+     user_target  =  paths .work .join ("user_target" )
452+     user_target .write ("user-data" )
453+     link_file  =  paths .work .join (utils .ALT_FILE1 )
454+     link_file .mksymlinkto (user_target )
455+     # now test-file -> user_target 
456+     alt_file  =  yadm_dir .join ("alt" ).join (f"{ utils .ALT_FILE1 }  )
457+     alt_file .write ("alt-data" , ensure = True )
458+     run  =  runner ([paths .pgm , "-Y" , yadm_dir , "--yadm-data" , yadm_data , "alt" ])
459+     assert  run .success 
460+     assert  os .path .realpath (str (link_file )) ==  str (user_target )
461+     assert  link_file .read () ==  "user-data" 
462+ 
463+ 
464+ @pytest .mark .usefixtures ("ds1_copy" ) 
465+ def  test_alt_skips_correct_symlink_without_touching (runner , paths ):
466+     """Optimization: yadm alt skips already-correct symlinks (no filesystem ops).""" 
467+     yadm_dir , yadm_data  =  setup_standard_yadm_dir (paths )
468+     alt_file  =  yadm_dir .join ("alt" ).join (f"{ utils .ALT_FILE1 }  )
469+     alt_file .write ("alt-data" , ensure = True )
470+     runner ([paths .pgm , "-Y" , yadm_dir , "--yadm-data" , yadm_data , "add" , alt_file ])
471+     runner ([paths .pgm , "-Y" , yadm_dir , "--yadm-data" , yadm_data , "alt" ])
472+     link_file  =  paths .work .join (utils .ALT_FILE1 )
473+     mtime_before  =  link_file .lstat ().mtime 
474+     runner ([paths .pgm , "-Y" , yadm_dir , "--yadm-data" , yadm_data , "alt" ])
475+     assert  link_file .lstat ().mtime  ==  mtime_before 
0 commit comments