@@ -519,55 +519,112 @@ def test_add_from_fs_base_dir_key_not_dict(
519
519
assert data == initial_config_data
520
520
521
521
522
- # Next: Integration style test with libvcs create_git_remote_repo
523
- @pytest .mark .skip (
524
- reason = "libvcs pytest plugin not available in this test environment yet"
525
- )
522
+ # @pytest.mark.skip(
523
+ # reason="libvcs pytest plugin not available in this test environment yet"
524
+ # )
526
525
def test_add_from_fs_integration_with_libvcs (
527
- # create_git_remote_repo, # This fixture would come from libvcs.pytest_plugin
528
- tmp_path : pathlib .Path , # Using tmp_path for manual git setup for now
529
- cwd_path_fs : pathlib .Path , # Mocked CWD
530
- mock_find_home_config_files_fs : t .Any ,
526
+ tmp_path : pathlib .Path ,
527
+ cwd_path_fs : pathlib .Path , # Mocked CWD, ensures config saved in predictable temp loc
528
+ mock_find_home_config_files_fs : t .Any , # To control config loading behavior
531
529
caplog : LogCaptureFixture ,
530
+ # git_commit_envvars: t.Mapping[str, str], # from libvcs if making commits
532
531
) -> None :
533
- """Test add_from_filesystem with actual git repositories created by libvcs (or manually)."""
534
- mock_find_home_config_files_fs .return_value = []
535
- scan_dir = cwd_path_fs / "integration_scan"
536
- scan_dir .mkdir (exist_ok = True )
537
- config_file = cwd_path_fs / ".vcspull.yaml"
532
+ """Test add_from_filesystem with actual git repos on the filesystem.
533
+
534
+ This test does not mock os.walk or get_git_origin_url.
535
+ It relies on conftest.py to set up a clean git environment (home, gitconfig).
536
+ """
537
+ mock_find_home_config_files_fs .return_value = [] # Default to CWD config
538
+ config_file_path = cwd_path_fs / ".vcspull.yaml"
539
+
540
+ scan_dir = tmp_path / "actual_projects_integration"
541
+ scan_dir .mkdir ()
542
+
543
+ # Repo 1: project_one
544
+ repo1_url = "https://example.com/integration/project_one.git"
545
+ repo1_name = "project_one"
546
+ repo1_dir = scan_dir / repo1_name
547
+ repo1_dir .mkdir ()
548
+ # Environment for subprocess.run should be clean thanks to libvcs fixtures in conftest
549
+ subprocess .run (
550
+ ["git" , "init" ], cwd = repo1_dir , check = True , capture_output = True , text = True
551
+ )
552
+ subprocess .run (
553
+ ["git" , "remote" , "add" , "origin" , repo1_url ],
554
+ cwd = repo1_dir ,
555
+ check = True ,
556
+ capture_output = True ,
557
+ text = True ,
558
+ )
538
559
539
- # Manually create a git repo as libvcs fixture is not directly usable here
540
- repo1_path = scan_dir / "actual_repo1"
541
- repo1_path .mkdir ()
542
- repo1_url = "https://gitserver.com/user/actual_repo1.git"
543
- try :
544
- subprocess .run (["git" , "init" ], cwd = repo1_path , check = True , capture_output = True )
545
- subprocess .run (
546
- ["git" , "remote" , "add" , "origin" , repo1_url ],
547
- cwd = repo1_path ,
548
- check = True ,
549
- capture_output = True ,
550
- )
551
- except (subprocess .CalledProcessError , FileNotFoundError ) as e :
552
- pytest .skip (f"git CLI not available or failed to init repo: { e } " )
560
+ # Repo 2: project_two (nested)
561
+ repo2_url = "git@example.com:integration/project_two.git"
562
+ repo2_name = "project_two"
563
+ nested_dir = scan_dir / "nested_group"
564
+ nested_dir .mkdir ()
565
+ repo2_dir = nested_dir / repo2_name
566
+ repo2_dir .mkdir ()
567
+ subprocess .run (
568
+ ["git" , "init" ], cwd = repo2_dir , check = True , capture_output = True , text = True
569
+ )
570
+ subprocess .run (
571
+ ["git" , "remote" , "add" , "origin" , repo2_url ],
572
+ cwd = repo2_dir ,
573
+ check = True ,
574
+ capture_output = True ,
575
+ text = True ,
576
+ )
553
577
554
- expected_base_key = str (scan_dir .resolve ()) + "/"
578
+ # Repo 3: project_three (no remote)
579
+ repo3_name = "project_three"
580
+ repo3_dir = scan_dir / repo3_name
581
+ repo3_dir .mkdir ()
582
+ subprocess .run (
583
+ ["git" , "init" ], cwd = repo3_dir , check = True , capture_output = True , text = True
584
+ )
585
+
586
+ # Repo 4: not_a_git_repo
587
+ not_a_repo_dir = scan_dir / "not_a_git_repo"
588
+ not_a_repo_dir .mkdir ()
589
+ (not_a_repo_dir / "some_file.txt" ).write_text ("hello" )
555
590
556
591
add_from_filesystem (
557
592
scan_dir_str = str (scan_dir ),
558
- config_file_path_str = None ,
593
+ config_file_path_str = None , # Uses default (cwd_path_fs / ".vcspull.yaml")
559
594
recursive = True ,
560
- base_dir_key_arg = None ,
561
- yes = True ,
595
+ base_dir_key_arg = None , # Infer
596
+ yes = True , # Auto-confirm
562
597
)
563
598
599
+ assert config_file_path .exists ()
600
+ with open (config_file_path ) as f :
601
+ data = yaml .safe_load (f )
602
+
603
+ expected_base_key = str (scan_dir .resolve ()) + "/"
604
+
605
+ assert expected_base_key in data
606
+ assert repo1_name in data [expected_base_key ]
607
+ assert data [expected_base_key ][repo1_name ] == repo1_url
608
+
609
+ assert repo2_name in data [expected_base_key ]
610
+ assert data [expected_base_key ][repo2_name ] == repo2_url
611
+
612
+ assert repo3_name not in data [expected_base_key ] # No remote
613
+ assert "not_a_git_repo" not in data [expected_base_key ]
614
+
615
+ assert f"Found .git in { repo1_dir } " in caplog .text
616
+ assert f"Found .git in { repo2_dir } " in caplog .text
617
+ assert f"Found .git in { repo3_dir } " in caplog .text
618
+ assert f"Could not get origin URL for { repo3_dir } " in caplog .text
564
619
assert (
565
- f"Adding 'actual_repo1 ' ({ repo1_url } ) under '{ expected_base_key } '"
620
+ f"Adding '{ repo1_name } ' ({ repo1_url } ) under '{ expected_base_key } '"
566
621
in caplog .text
567
622
)
568
- with open (config_file ) as f :
569
- data = yaml .safe_load (f )
570
- assert data [expected_base_key ]["actual_repo1" ] == repo1_url
623
+ assert (
624
+ f"Adding '{ repo2_name } ' ({ repo2_url } ) under '{ expected_base_key } '"
625
+ in caplog .text
626
+ )
627
+ assert f"Successfully updated { config_file_path } " in caplog .text
571
628
572
629
573
630
# - scan_dir being relative to a mocked home directory for key generation
0 commit comments