@@ -1707,3 +1707,96 @@ fn cli_sync_new_remote_url() -> MgitResult<()> {
1707
1707
std:: fs:: remove_dir_all ( & path) . unwrap ( ) ;
1708
1708
Ok ( ( ) )
1709
1709
}
1710
+
1711
+ /// 测试内容:
1712
+ /// 1、运行命令 mgit sync <path> --no-checkout
1713
+ /// 2、检查配置的稀疏检出是否和预期匹配
1714
+ /// 3、根目录是仓库
1715
+ ///
1716
+ /// 测试目录结构:
1717
+ /// cli_sync_with_sparse_checkout_dirs(.git)
1718
+ /// ├─Doc
1719
+ /// ├─img
1720
+ /// └─README.md
1721
+ #[ test]
1722
+ fn cli_sync_with_sparse_checkout_dirs ( ) -> MgitResult < ( ) > {
1723
+ let path = env:: current_dir ( )
1724
+ . unwrap ( )
1725
+ . join ( "target" )
1726
+ . join ( "tmp" )
1727
+ . join ( "cli_sync_with_sparse_checkout_dirs" ) ;
1728
+ let input_path = path. to_str ( ) . unwrap ( ) ;
1729
+
1730
+ let _ = std:: fs:: remove_dir_all ( & path) ;
1731
+ std:: fs:: create_dir_all ( & path) . unwrap ( ) ;
1732
+
1733
+ let mut toml_string = TomlBuilder :: default ( )
1734
+ . default_branch ( "develop" )
1735
+ . join_repo ( "." , & CSBOOKS_REPO , Some ( "master" ) , None , None )
1736
+ . build ( ) ;
1737
+ let sparse_checkout_dirs = r#"sparse-checkout-dirs = ["Doc", "/*.md"]"# ;
1738
+ toml_string. push_str ( sparse_checkout_dirs) ;
1739
+
1740
+ let config_file = path. join ( ".gitrepos" ) ;
1741
+ std:: fs:: write ( & config_file, toml_string. trim ( ) ) . expect ( failed_message:: WRITE_FILE ) ;
1742
+
1743
+ // initialize the repositories tree
1744
+ ops:: sync_repo (
1745
+ SyncOptions :: new (
1746
+ Some ( input_path) ,
1747
+ None :: < PathBuf > ,
1748
+ None ,
1749
+ None ,
1750
+ None ,
1751
+ None ,
1752
+ Some ( true ) ,
1753
+ None ,
1754
+ Some ( true ) ,
1755
+ None ,
1756
+ ) ,
1757
+ TestProgress ,
1758
+ ) ?;
1759
+
1760
+ // compaire sparse-checkout list
1761
+ if let Ok ( output) = exec_cmd ( & path, "git" , & [ "sparse-checkout" , "list" ] ) {
1762
+ assert_eq ! ( output. contains( "Doc" ) , true ) ;
1763
+ assert_eq ! ( output. contains( "img" ) , false ) ;
1764
+ assert_eq ! ( output. contains( "/*.md" ) , true ) ;
1765
+
1766
+ assert_eq ! ( path. join( "Doc" ) . exists( ) , true ) ;
1767
+ assert_eq ! ( path. join( "img" ) . exists( ) , false ) ;
1768
+ assert_eq ! ( path. join( "README.md" ) . exists( ) , true ) ;
1769
+ } else {
1770
+ panic ! ( "{}" , failed_message:: GIT_SPARSE_CHECKOUT ) ;
1771
+ }
1772
+
1773
+ toml_string = toml_string. replace ( sparse_checkout_dirs, "" ) ;
1774
+ std:: fs:: write ( & config_file, toml_string. trim ( ) ) . expect ( failed_message:: WRITE_FILE ) ;
1775
+ // excute sync
1776
+ ops:: sync_repo (
1777
+ SyncOptions :: new (
1778
+ Some ( input_path) ,
1779
+ None :: < PathBuf > ,
1780
+ None ,
1781
+ None ,
1782
+ None ,
1783
+ None ,
1784
+ None ,
1785
+ None ,
1786
+ None ,
1787
+ Some ( true ) ,
1788
+ ) ,
1789
+ TestProgress ,
1790
+ ) ?;
1791
+
1792
+ // compaire sparse-checkout list
1793
+ let res = exec_cmd ( & path, "git" , & [ "sparse-checkout" , "list" ] ) ;
1794
+ assert ! ( res. is_err( ) ) ;
1795
+ assert_eq ! ( path. join( "Doc" ) . exists( ) , true ) ;
1796
+ assert_eq ! ( path. join( "img" ) . exists( ) , true ) ;
1797
+ assert_eq ! ( path. join( "README.md" ) . exists( ) , true ) ;
1798
+
1799
+ // clean-up
1800
+ std:: fs:: remove_dir_all ( & path) . unwrap ( ) ;
1801
+ Ok ( ( ) )
1802
+ }
0 commit comments