Skip to content

tests(config-variations): Git schemes in repo URLs #490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/url/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Detect VCS from `git`, `hg`, and `svn` URLs.
[ParserMatch(vcs='git', match=GitURL(...))]

>>> registry.match('[email protected]:plasma/plasma-sdk.git', is_explicit=True)
[]
[ParserMatch(vcs='git', match=GitURL(...))]

>>> registry.match('git+ssh://[email protected]:plasma/plasma-sdk.git')
[ParserMatch(vcs='git', match=GitURL(...))]
Expand Down
20 changes: 20 additions & 0 deletions src/libvcs/_internal/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ def create_project(
) -> HgSync: ...


@t.overload
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider using a single function signature with union types to reduce overload duplication and simplify the API while maintaining functionality

You can reduce overload duplication by declaring a single function signature that uses the union types for both the parameter and the return value. For example, remove the extra overload and use this unified signature:

def create_project(
    *,
    url: str,
    path: StrPath,
    vcs: VCSLiteral | None = None,
    progress_callback: ProgressCallbackProtocol | None = None,
    **kwargs: t.Any,
) -> GitSync | HgSync | SvnSync:
    ...

This minimizes duplicate parameters and keeps the API clear while preserving all functionality.

def create_project(
*,
url: str,
path: StrPath,
vcs: None = None,
progress_callback: ProgressCallbackProtocol | None = None,
**kwargs: dict[t.Any, t.Any],
) -> GitSync | HgSync | SvnSync: ...


def create_project(
*,
url: str,
Expand Down Expand Up @@ -98,6 +109,15 @@ def create_project(
... path=tmp_path
... )

>>> isinstance(r, GitSync)
True

It also supports unprefixed SSH-style Git URLs:

>>> r = create_project(
... url='[email protected]:tmux-python/tmuxp.git',
... path=tmp_path
... )
>>> isinstance(r, GitSync)
True
"""
Expand Down
6 changes: 4 additions & 2 deletions src/libvcs/url/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
""",
re.VERBOSE,
),
is_explicit=True,
),
# ends with .git. Including ones starting with https://
# e.g. https://github.com/vcs-python/libvcs.git
Expand All @@ -77,6 +78,7 @@
re.VERBOSE,
),
defaults={"username": "git"},
is_explicit=True,
),
# SCP-style URLs, e.g. git@
]
Expand Down Expand Up @@ -392,7 +394,7 @@ def is_valid(cls, url: str, is_explicit: bool | None = None) -> bool:
>>> GitBaseURL.is_valid(
... url='[email protected]:vcs-python/libvcs.git', is_explicit=True
... )
False
True

In this case, check :meth:`GitPipURL.is_valid` or :meth:`GitURL.is_valid`'s
examples.
Expand Down Expand Up @@ -764,7 +766,7 @@ def is_valid(cls, url: str, is_explicit: bool | None = None) -> bool:
>>> GitURL.is_valid(
... url='[email protected]:vcs-python/libvcs.git', is_explicit=True
... )
False
True

You could create a GitHub rule that consider github.com hostnames to be
exclusively git:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ def test_create_project(
else:
repo = create_project(**repo_dict)
assert isinstance(repo, repo_class)


def test_create_project_infer_scp_git(tmp_path: pathlib.Path) -> None:
"""Test create_project infers Git VCS for SCP-style URLs."""
url = "[email protected]:tmux-python/tmuxp.git"
path = tmp_path / "tmuxp_repo"
repo = create_project(url=url, path=path)
assert isinstance(repo, GitSync)
2 changes: 2 additions & 0 deletions tests/url/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class DetectVCSFixture(t.NamedTuple):
"codecommit::ap-northeast-1://MyDemoRepo",
"https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
"ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
# plain SCP-style Git URLs should be recognized explicitly
"[email protected]:tmux-python/tmuxp.git",
]
],
*[
Expand Down