@@ -431,7 +431,7 @@ def is_valid(cls, url: str, is_explicit: Optional[bool] = None) -> bool:
431
431
Examples
432
432
--------
433
433
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.
435
435
436
436
>>> GitPipURL.is_valid(url='https://github.com/vcs-python/libvcs.git')
437
437
False
@@ -482,6 +482,55 @@ class GitURL(GitPipURL, GitBaseURL, URLProtocol, SkipDefaultFieldsReprMixin):
482
482
_matchers = {m .label : m for m in [* DEFAULT_MATCHERS , * PIP_DEFAULT_MATCHERS ]}
483
483
)
484
484
485
+ @classmethod
486
+ def is_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
+ return super ().is_valid (url = url , is_explicit = is_explicit )
533
+
485
534
def to_url (self ) -> str :
486
535
"""Return a ``git(1)``-compatible URL. Can be used with ``git clone``.
487
536
0 commit comments