diff --git a/src/vcspull/config.py b/src/vcspull/config.py index 2d3ffc9a..8fabc460 100644 --- a/src/vcspull/config.py +++ b/src/vcspull/config.py @@ -685,11 +685,17 @@ def filter_repos( repo_list: list[ConfigDict] = [] if path: + path_str = str(path) + if "~" in path_str or "$" in path_str: + path_str = str(expand_dir(pathlib.Path(path_str))) + else: + path_str = str(pathlib.Path(path_str)) repo_list.extend( [ r for r in config - if fnmatch.fnmatch(str(pathlib.Path(r["path"]).parent), str(path)) + if fnmatch.fnmatch(str(pathlib.Path(r["path"]).parent), path_str) + or fnmatch.fnmatch(str(r["path"]), path_str) ], ) diff --git a/tests/test_repo.py b/tests/test_repo.py index f6ccd49a..e19e91f4 100644 --- a/tests/test_repo.py +++ b/tests/test_repo.py @@ -24,6 +24,26 @@ def test_filter_dir() -> None: assert r["name"] == "kaptan" +def test_filter_dir_exact_repo_path() -> None: + """`filter_repos` filter by exact full repo path (e.g. after zsh glob expansion).""" + repo_list = filter_repos( + fixtures.config_dict_expanded, + path="/home/me/myproject/github_projects/kaptan", + ) + assert len(repo_list) == 1 + assert repo_list[0]["name"] == "kaptan" + + +def test_filter_dir_workspace_root_trailing_slash() -> None: + """`filter_repos` filter by workspace root path with trailing slash.""" + repo_list = filter_repos( + fixtures.config_dict_expanded, + path="/home/me/myproject/github_projects/", + ) + assert len(repo_list) == 1 + assert repo_list[0]["name"] == "kaptan" + + def test_filter_name() -> None: """`filter_repos` filter by name.""" repo_list = filter_repos(fixtures.config_dict_expanded, name=".vim")