@@ -372,7 +372,7 @@ def mock_expand_dir_func(dir_path_obj: pathlib.Path, cwd: t.Any = None) -> pathl
372
372
return dir_path_obj .resolve ()
373
373
# Handle tilde expansion based on mocked home
374
374
if str (dir_path_obj ).startswith ("~" ):
375
- return (mock_home / str (dir_path_obj ).lstrip ("~/\ " )).resolve ()
375
+ return (mock_home / str (dir_path_obj ).lstrip ("~/" )).resolve ()
376
376
return ( (cwd () if callable (cwd ) else cwd ) / dir_path_obj ).resolve ()
377
377
378
378
mocker .patch ("vcspull.cli.add.expand_dir" , side_effect = mock_expand_dir_func )
@@ -471,3 +471,54 @@ def test_add_repo_base_dir_key_not_dict(
471
471
# Placeholder for tests
472
472
def test_example_add_placeholder () -> None :
473
473
assert True
474
+
475
+
476
+ def test_add_repo_base_dir_key_is_none_and_target_path_is_url (
477
+ tmp_path : pathlib .Path ,
478
+ cwd_path : pathlib .Path , # Mocked CWD
479
+ mock_find_home_config_files : t .Any ,
480
+ caplog : LogCaptureFixture
481
+ ) -> None :
482
+ """Test when base_dir_key is None and target_path_str (URL) is provided."""
483
+ # This scenario should default to base_dir_key = "./" relative to CWD
484
+ mock_find_home_config_files .return_value = [] # No home config
485
+ config_file = cwd_path / ".vcspull.yaml"
486
+
487
+ add_repo (
488
+ repo_name_or_url = "myrepo" ,
489
+ target_path_str = "https://example.com/url.git" , # This is the URL
490
+ config_file_path_str = None , # Test default to CWD config
491
+ base_dir_key = None # Explicitly None
492
+ )
493
+
494
+ assert config_file .exists ()
495
+ with open (config_file , "r" ) as f :
496
+ data = yaml .safe_load (f )
497
+ assert "./" in data
498
+ assert data ["./" ]["myrepo" ] == "https://example.com/url.git"
499
+ assert f"Successfully added 'myrepo' ('https://example.com/url.git') to { config_file } under './'" in caplog .text
500
+
501
+
502
+ def test_add_repo_base_dir_key_is_none_and_repo_name_or_url_is_url (
503
+ tmp_path : pathlib .Path ,
504
+ cwd_path : pathlib .Path , # Mocked CWD
505
+ mock_find_home_config_files : t .Any ,
506
+ caplog : LogCaptureFixture
507
+ ) -> None :
508
+ """Test when base_dir_key is None and repo_name_or_url (first arg) is a URL."""
509
+ mock_find_home_config_files .return_value = []
510
+ config_file = cwd_path / ".vcspull.yaml"
511
+
512
+ add_repo (
513
+ repo_name_or_url = "https://example.com/url_as_first_arg.git" ,
514
+ target_path_str = None , # Second arg is None
515
+ config_file_path_str = None ,
516
+ base_dir_key = None
517
+ )
518
+ assert config_file .exists ()
519
+ with open (config_file , "r" ) as f :
520
+ data = yaml .safe_load (f )
521
+ assert "./" in data
522
+ # Name is inferred from URL
523
+ assert data ["./" ][ "url_as_first_arg" ] == "https://example.com/url_as_first_arg.git"
524
+ assert f"Successfully added 'url_as_first_arg' ('https://example.com/url_as_first_arg.git') to { config_file } under './'" in caplog .text
0 commit comments