@@ -900,6 +900,133 @@ def mock_run_side_effect(*args, **kwargs):
900900 assert "main" in push_calls [0 ][0 ][0 ]
901901
902902
903+ def test_repo_sync_dot_from_repo_root (tmp_path , temp_repos_dir , monkeypatch ):
904+ """Test syncing with '.' resolves to the repo at the current directory."""
905+ config_path = tmp_path / ".config" / "dbx-python-cli" / "config.toml"
906+ config_path .parent .mkdir (parents = True , exist_ok = True )
907+ repos_dir_str = str (temp_repos_dir ).replace ("\\ " , "/" )
908+ config_content = f"""
909+ [repo]
910+ base_dir = "{ repos_dir_str } "
911+
912+ [repo.groups.test]
913+ repos = [
914+ "git@github.com:mongodb/mongo-python-driver.git",
915+ ]
916+ """
917+ config_path .write_text (config_content )
918+
919+ # Create mock repository
920+ group_dir = temp_repos_dir / "test"
921+ repo_dir = group_dir / "mongo-python-driver"
922+ repo_dir .mkdir (parents = True )
923+ (repo_dir / ".git" ).mkdir ()
924+
925+ # Change into the repo root so that "." resolves to it
926+ monkeypatch .chdir (repo_dir )
927+
928+ with patch ("dbx_python_cli.utils.repo.get_config_path" ) as mock_get_path :
929+ with patch ("dbx_python_cli.commands.sync.subprocess.run" ) as mock_run :
930+ mock_get_path .return_value = config_path
931+
932+ def mock_run_side_effect (* args , ** kwargs ):
933+ cmd = args [0 ]
934+ if "remote" in cmd and "add" not in cmd :
935+ return subprocess .CompletedProcess (
936+ cmd , 0 , stdout = "origin\n upstream\n " , stderr = ""
937+ )
938+ elif "branch" in cmd and "--show-current" in cmd :
939+ return subprocess .CompletedProcess (cmd , 0 , stdout = "main\n " , stderr = "" )
940+ else :
941+ return subprocess .CompletedProcess (cmd , 0 , stdout = "" , stderr = "" )
942+
943+ mock_run .side_effect = mock_run_side_effect
944+
945+ result = runner .invoke (app , ["sync" , "." ])
946+ assert result .exit_code == 0
947+ assert "Syncing mongo-python-driver" in result .stdout
948+ assert "Synced and pushed successfully" in result .stdout
949+
950+
951+ def test_repo_sync_dot_from_repo_subdirectory (tmp_path , temp_repos_dir , monkeypatch ):
952+ """Test that '.' resolves correctly when run from inside a repo subdirectory."""
953+ config_path = tmp_path / ".config" / "dbx-python-cli" / "config.toml"
954+ config_path .parent .mkdir (parents = True , exist_ok = True )
955+ repos_dir_str = str (temp_repos_dir ).replace ("\\ " , "/" )
956+ config_content = f"""
957+ [repo]
958+ base_dir = "{ repos_dir_str } "
959+
960+ [repo.groups.test]
961+ repos = [
962+ "git@github.com:mongodb/mongo-python-driver.git",
963+ ]
964+ """
965+ config_path .write_text (config_content )
966+
967+ # Create mock repository with a subdirectory
968+ group_dir = temp_repos_dir / "test"
969+ repo_dir = group_dir / "mongo-python-driver"
970+ subdir = repo_dir / "src" / "pymongo"
971+ subdir .mkdir (parents = True )
972+ (repo_dir / ".git" ).mkdir ()
973+
974+ # Change into a subdirectory of the repo
975+ monkeypatch .chdir (subdir )
976+
977+ with patch ("dbx_python_cli.utils.repo.get_config_path" ) as mock_get_path :
978+ with patch ("dbx_python_cli.commands.sync.subprocess.run" ) as mock_run :
979+ mock_get_path .return_value = config_path
980+
981+ def mock_run_side_effect (* args , ** kwargs ):
982+ cmd = args [0 ]
983+ if "remote" in cmd and "add" not in cmd :
984+ return subprocess .CompletedProcess (
985+ cmd , 0 , stdout = "origin\n upstream\n " , stderr = ""
986+ )
987+ elif "branch" in cmd and "--show-current" in cmd :
988+ return subprocess .CompletedProcess (cmd , 0 , stdout = "main\n " , stderr = "" )
989+ else :
990+ return subprocess .CompletedProcess (cmd , 0 , stdout = "" , stderr = "" )
991+
992+ mock_run .side_effect = mock_run_side_effect
993+
994+ result = runner .invoke (app , ["sync" , "." ])
995+ assert result .exit_code == 0
996+ assert "Syncing mongo-python-driver" in result .stdout
997+ assert "Synced and pushed successfully" in result .stdout
998+
999+
1000+ def test_repo_sync_dot_not_in_managed_repo (tmp_path , temp_repos_dir , monkeypatch ):
1001+ """Test that '.' in an unmanaged directory gives a clear error."""
1002+ config_path = tmp_path / ".config" / "dbx-python-cli" / "config.toml"
1003+ config_path .parent .mkdir (parents = True , exist_ok = True )
1004+ repos_dir_str = str (temp_repos_dir ).replace ("\\ " , "/" )
1005+ config_content = f"""
1006+ [repo]
1007+ base_dir = "{ repos_dir_str } "
1008+
1009+ [repo.groups.test]
1010+ repos = [
1011+ "git@github.com:mongodb/mongo-python-driver.git",
1012+ ]
1013+ """
1014+ config_path .write_text (config_content )
1015+
1016+ # Change into a directory that is NOT a managed repo
1017+ unrelated_dir = tmp_path / "unrelated"
1018+ unrelated_dir .mkdir ()
1019+ monkeypatch .chdir (unrelated_dir )
1020+
1021+ with patch ("dbx_python_cli.utils.repo.get_config_path" ) as mock_get_path :
1022+ mock_get_path .return_value = config_path
1023+
1024+ result = runner .invoke (app , ["sync" , "." ])
1025+ assert result .exit_code == 1
1026+ output = result .stdout + result .stderr
1027+ assert "No managed repository found" in output
1028+
1029+
9031030def test_repo_sync_group (tmp_path , temp_repos_dir ):
9041031 """Test syncing all repositories in a group."""
9051032 config_path = tmp_path / ".config" / "dbx-python-cli" / "config.toml"
0 commit comments