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

Merged
merged 2 commits into from
Jun 22, 2025
Merged
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
7 changes: 6 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ $ pip install --user --upgrade --pre libvcs

## libvcs 0.36.x (unreleased)

- _Notes on upcoming releases will be added here_
### Iprovements

- Add support for SCP-style Git URLs without requiring `git+ssh://` prefix (#490)
- URLs like `git@github.com:org/repo.git` are now recognized as Git repositories
- `create_project()` can now auto-detect VCS type for these URLs
- 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)

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

Expand Down
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('git@invent.kde.org:plasma/plasma-sdk.git', is_explicit=True)
[]
[ParserMatch(vcs='git', match=GitURL(...))]

>>> registry.match('git+ssh://git@invent.kde.org: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
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='git@github.com: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='git@github.com: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='git@github.com: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 = "git@github.com: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
"git@github.com:tmux-python/tmuxp.git",
]
],
*[
Expand Down