Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52759be

Browse files
committed
tests(GitURL): is_valid examples
1 parentc28fe29 commit52759be

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

‎libvcs/parse/git.py‎

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def is_valid(cls, url: str, is_explicit: Optional[bool] = None) -> bool:
431431
Examples
432432
--------
433433
434-
Will not match normal ``git(1)`` URLs, use :meth:`GitURL.is_valid` for that.
434+
Will**not** match normal ``git(1)`` URLs, use :meth:`GitURL.is_valid` for that.
435435
436436
>>> GitPipURL.is_valid(url='https://github.com/vcs-python/libvcs.git')
437437
False
@@ -482,6 +482,55 @@ class GitURL(GitPipURL, GitBaseURL, URLProtocol, SkipDefaultFieldsReprMixin):
482482
_matchers={m.label:mformin [*DEFAULT_MATCHERS,*PIP_DEFAULT_MATCHERS]}
483483
)
484484

485+
@classmethod
486+
defis_valid(cls,url:str,is_explicit:Optional[bool]=None)->bool:
487+
"""Whether URL is compatible included Git URL matchers or not.
488+
489+
Examples
490+
--------
491+
492+
**Will** match normal ``git(1)`` URLs, use :meth:`GitURL.is_valid` for that.
493+
494+
>>> GitURL.is_valid(url='https://github.com/vcs-python/libvcs.git')
495+
True
496+
497+
>>> GitURL.is_valid(url='git@github.com:vcs-python/libvcs.git')
498+
True
499+
500+
Pip-style URLs:
501+
502+
>>> GitURL.is_valid(url='git+https://github.com/vcs-python/libvcs.git')
503+
True
504+
505+
>>> GitURL.is_valid(url='git+ssh://git@github.com:vcs-python/libvcs.git')
506+
True
507+
508+
>>> GitURL.is_valid(url='notaurl')
509+
False
510+
511+
**Explicit VCS detection**
512+
513+
Pip-style URLs are prefixed with the VCS name in front, so its matchers can
514+
unambigously narrow the type of VCS:
515+
516+
>>> GitURL.is_valid(
517+
... url='git+ssh://git@github.com:vcs-python/libvcs.git', is_explicit=True
518+
... )
519+
True
520+
521+
Below, while it's github, that doesn't necessarily mean that the URL itself
522+
is conclusively a git URL:
523+
524+
>>> GitURL.is_valid(
525+
... url='git@github.com:vcs-python/libvcs.git', is_explicit=True
526+
... )
527+
False
528+
529+
You could create a GitHub matcher that consider github.com hostnames to be
530+
exclusively.
531+
"""
532+
returnsuper().is_valid(url=url,is_explicit=is_explicit)
533+
485534
defto_url(self)->str:
486535
"""Return a ``git(1)``-compatible URL. Can be used with ``git clone``.
487536

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp