Skip to content

Commit 00acfa1

Browse files
authored
tests(config-variations): Git schemes in repo URLs (#490)
Related to vcs-python/vcspull#49, vcs-python/vcspull#426 **In main repo URLs:** Main repo URLs require `libvcs.url.git.GitURL` support: Scheme: `user@domain.tld:org/repo.git` Example: `git@github.com:tmux-python/tmuxp.git` Note: The workaround is to prepend `git+ssh://git@github.com:tmux-python/tmuxp.git`
2 parents 0cf3504 + de59052 commit 00acfa1

File tree

6 files changed

+41
-4
lines changed

6 files changed

+41
-4
lines changed

CHANGES

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ $ pip install --user --upgrade --pre libvcs
1111

1212
## libvcs 0.36.x (unreleased)
1313

14-
- _Notes on upcoming releases will be added here_
14+
### Iprovements
15+
16+
- Add support for SCP-style Git URLs without requiring `git+ssh://` prefix (#490)
17+
- URLs like `git@github.com:org/repo.git` are now recognized as Git repositories
18+
- `create_project()` can now auto-detect VCS type for these URLs
19+
- Addresses issues reported in [vcspull#49](https://github.com/vcs-python/vcspull/issues/49) and [vcspull#426](https://github.com/vcs-python/vcspull/pull/426)
1520

1621
<!-- Maintainers, insert changes / features for the next release here -->
1722

docs/url/registry.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 20 additions & 0 deletions
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy