Skip to content

Commit bd93848

Browse files
committed
Make core git URL rules explicit; support plain SCP-style git URLs as explicit VCS matches; update docs, tests, and create_project overloads
1 parent ba36391 commit bd93848

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

docs/url/registry.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Detect VCS from `git`, `hg`, and `svn` URLs.
1212
[ParserMatch(vcs='git', match=GitURL(...))]
1313

1414
>>> registry.match('git@invent.kde.org:plasma/plasma-sdk.git', is_explicit=True)
15-
[]
15+
[ParserMatch(vcs='git', match=GitURL(...))]
1616

1717
>>> registry.match('git+ssh://git@invent.kde.org:plasma/plasma-sdk.git')
1818
[ParserMatch(vcs='git', match=GitURL(...))]

src/libvcs/_internal/shortcuts.py

+20
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ def create_project(
6868
) -> HgSync: ...
6969

7070

71+
@t.overload
72+
def create_project(
73+
*,
74+
url: str,
75+
path: StrPath,
76+
vcs: None = None,
77+
progress_callback: ProgressCallbackProtocol | None = None,
78+
**kwargs: dict[t.Any, t.Any],
79+
) -> GitSync | HgSync | SvnSync: ...
80+
81+
7182
def create_project(
7283
*,
7384
url: str,
@@ -98,6 +109,15 @@ def create_project(
98109
... path=tmp_path
99110
... )
100111
112+
>>> isinstance(r, GitSync)
113+
True
114+
115+
It also supports unprefixed SSH-style Git URLs:
116+
117+
>>> r = create_project(
118+
... url='git@github.com:tmux-python/tmuxp.git',
119+
... path=tmp_path
120+
... )
101121
>>> isinstance(r, GitSync)
102122
True
103123
"""

src/libvcs/url/git.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
""",
6262
re.VERBOSE,
6363
),
64+
is_explicit=True,
6465
),
6566
# ends with .git. Including ones starting with https://
6667
# e.g. https://github.com/vcs-python/libvcs.git
@@ -77,6 +78,7 @@
7778
re.VERBOSE,
7879
),
7980
defaults={"username": "git"},
81+
is_explicit=True,
8082
),
8183
# SCP-style URLs, e.g. git@
8284
]
@@ -392,7 +394,7 @@ def is_valid(cls, url: str, is_explicit: bool | None = None) -> bool:
392394
>>> GitBaseURL.is_valid(
393395
... url='git@github.com:vcs-python/libvcs.git', is_explicit=True
394396
... )
395-
False
397+
True
396398
397399
In this case, check :meth:`GitPipURL.is_valid` or :meth:`GitURL.is_valid`'s
398400
examples.
@@ -764,7 +766,7 @@ def is_valid(cls, url: str, is_explicit: bool | None = None) -> bool:
764766
>>> GitURL.is_valid(
765767
... url='git@github.com:vcs-python/libvcs.git', is_explicit=True
766768
... )
767-
False
769+
True
768770
769771
You could create a GitHub rule that consider github.com hostnames to be
770772
exclusively git:

tests/test_shortcuts.py

+8
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,11 @@ def test_create_project(
7070
else:
7171
repo = create_project(**repo_dict)
7272
assert isinstance(repo, repo_class)
73+
74+
75+
def test_create_project_infer_scp_git(tmp_path: pathlib.Path) -> None:
76+
"""Test create_project infers Git VCS for SCP-style URLs."""
77+
url = "git@github.com:tmux-python/tmuxp.git"
78+
path = tmp_path / "tmuxp_repo"
79+
repo = create_project(url=url, path=path)
80+
assert isinstance(repo, GitSync)

tests/url/test_registry.py

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class DetectVCSFixture(t.NamedTuple):
5353
"codecommit::ap-northeast-1://MyDemoRepo",
5454
"https://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
5555
"ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/test",
56+
# plain SCP-style Git URLs should be recognized explicitly
57+
"git@github.com:tmux-python/tmuxp.git",
5658
]
5759
],
5860
*[

0 commit comments

Comments
 (0)