@@ -390,9 +390,67 @@ mod git2_ops_tests {
390390 . expect ( "add submodule" ) ;
391391
392392 let mut ops = Git2Operations :: new ( Some ( & harness. work_dir ) ) . expect ( "ops" ) ;
393- let entries = ops. read_gitmodules ( ) . expect ( "read_gitmodules" ) ;
393+ let mut entries = ops. read_gitmodules ( ) . expect ( "read_gitmodules" ) ;
394394 // write_gitmodules with the same entries should succeed without error
395395 ops. write_gitmodules ( & entries) . expect ( "write_gitmodules" ) ;
396+
397+ // Verify that updating `active` sets it in the git configuration
398+ // In .gitmodules the git2 fallback might name the submodule by its path 'lib/writesub'
399+ let name = if entries. get ( "write-sub" ) . is_some ( ) {
400+ "write-sub"
401+ } else {
402+ "lib/writesub"
403+ } ;
404+
405+ if let Some ( mut entry) = entries. get ( name) . cloned ( ) {
406+ entry. active = Some ( false ) ;
407+ entries. update_entry ( name. to_string ( ) , entry) ;
408+ }
409+ ops. write_gitmodules ( & entries) . expect ( "write_gitmodules active false" ) ;
410+
411+ // Check git2 config manually or via read_gitmodules? Actually read_gitmodules in git2
412+ // doesn't read active from .git/config, but wait, it is set in `.git/config`!
413+ let config_path = harness. work_dir . join ( ".git" ) . join ( "config" ) ;
414+ let config_content = std:: fs:: read_to_string ( & config_path) . expect ( "read git config" ) ;
415+ assert ! ( config_content. contains( "active = false" ) , "submodule should be inactive in config" ) ;
416+ }
417+
418+ #[ test]
419+ fn test_with_submodule_write_gitmodules_active_none ( ) {
420+ let harness = TestHarness :: new ( ) . expect ( "harness" ) ;
421+ harness. init_git_repo ( ) . expect ( "init repo" ) ;
422+ let remote = harness. create_test_remote ( "g2_write_sub_none" ) . expect ( "remote" ) ;
423+ let remote_url = format ! ( "file://{}" , remote. display( ) ) ;
424+
425+ harness
426+ . run_submod_success ( & [
427+ "add" ,
428+ & remote_url,
429+ "--name" ,
430+ "write-sub-none" ,
431+ "--path" ,
432+ "lib/writesubnone" ,
433+ ] )
434+ . expect ( "add submodule" ) ;
435+
436+ let mut ops = Git2Operations :: new ( Some ( & harness. work_dir ) ) . expect ( "ops" ) ;
437+ let mut entries = ops. read_gitmodules ( ) . expect ( "read_gitmodules" ) ;
438+
439+ let name = if entries. get ( "write-sub-none" ) . is_some ( ) {
440+ "write-sub-none"
441+ } else {
442+ "lib/writesubnone"
443+ } ;
444+
445+ if let Some ( mut entry) = entries. get ( name) . cloned ( ) {
446+ entry. active = None ;
447+ entries. update_entry ( name. to_string ( ) , entry) ;
448+ }
449+ ops. write_gitmodules ( & entries) . expect ( "write_gitmodules active none" ) ;
450+
451+ let config_path = harness. work_dir . join ( ".git" ) . join ( "config" ) ;
452+ let config_content = std:: fs:: read_to_string ( & config_path) . expect ( "read git config" ) ;
453+ assert ! ( !config_content. contains( "active =" ) , "submodule active should be untouched" ) ;
396454 }
397455}
398456
@@ -554,6 +612,46 @@ mod gix_ops_tests {
554612 ) ;
555613 }
556614
615+ #[ test]
616+ fn test_write_gitmodules_active_false ( ) {
617+ let harness = TestHarness :: new ( ) . expect ( "harness" ) ;
618+ harness. init_git_repo ( ) . expect ( "init repo" ) ;
619+ let mut ops = GixOperations :: new ( Some ( & harness. work_dir ) ) . expect ( "ops" ) ;
620+
621+ let mut entries = one_entry_entries ( ) ;
622+ if let Some ( mut entry) = entries. get ( "test-lib" ) . cloned ( ) {
623+ entry. active = Some ( false ) ;
624+ entries. update_entry ( "test-lib" . to_string ( ) , entry) ;
625+ }
626+
627+ ops. write_gitmodules ( & entries)
628+ . expect ( "write_gitmodules should succeed" ) ;
629+
630+ let content = std:: fs:: read_to_string ( harness. work_dir . join ( ".gitmodules" ) )
631+ . expect ( "read .gitmodules" ) ;
632+ assert ! (
633+ content. contains( "active = false" ) ,
634+ ".gitmodules should contain active = false"
635+ ) ;
636+ }
637+
638+ #[ test]
639+ fn test_write_gitmodules_active_none ( ) {
640+ let harness = TestHarness :: new ( ) . expect ( "harness" ) ;
641+ harness. init_git_repo ( ) . expect ( "init repo" ) ;
642+ let mut ops = GixOperations :: new ( Some ( & harness. work_dir ) ) . expect ( "ops" ) ;
643+
644+ let mut entries = one_entry_entries ( ) ;
645+ if let Some ( mut entry) = entries. get ( "test-lib" ) . cloned ( ) {
646+ entry. active = None ;
647+ entries. update_entry ( "test-lib" . to_string ( ) , entry) ;
648+ }
649+
650+ ops. write_gitmodules ( & entries) . expect ( "write_gitmodules" ) ;
651+ let content = std:: fs:: read_to_string ( harness. work_dir . join ( ".gitmodules" ) ) . expect ( "read" ) ;
652+ assert ! ( !content. contains( "active =" ) ) ;
653+ }
654+
557655 #[ test]
558656 fn test_write_gitmodules_empty_entries ( ) {
559657 let harness = TestHarness :: new ( ) . expect ( "harness" ) ;
0 commit comments