@@ -340,12 +340,73 @@ def to_url(self) -> str:
340340
341341
342342@dataclasses .dataclass (repr = False )
343- class GitURL (GitBaseURL , URLProtocol , SkipDefaultFieldsReprMixin ):
344- """Batteries included URL Parser. Supports git(1) and pip URLs."""
343+ class GitPipURL (GitBaseURL , URLProtocol , SkipDefaultFieldsReprMixin ):
344+ """Supports pip git URLs."""
345345
346346 # commit-ish (rev): tag, branch, ref
347347 rev : Optional [str ] = None
348348
349+ matchers = MatcherRegistry = MatcherRegistry (
350+ _matchers = {m .label : m for m in PIP_DEFAULT_MATCHERS }
351+ )
352+
353+ def to_url (self ) -> str :
354+ """Exports a pip-compliant URL.
355+
356+ Examples
357+ --------
358+
359+ >>> git_location = GitPipURL(
360+ ... url='git+ssh://git@bitbucket.example.com:7999/PROJ/repo.git'
361+ ... )
362+
363+ >>> git_location
364+ GitPipURL(url=git+ssh://git@bitbucket.example.com:7999/PROJ/repo.git,
365+ scheme=git+ssh,
366+ user=git,
367+ hostname=bitbucket.example.com,
368+ port=7999,
369+ path=PROJ/repo,
370+ suffix=.git,
371+ matcher=pip-url)
372+
373+ >>> git_location.path = 'libvcs/vcspull'
374+
375+ >>> git_location.to_url()
376+ 'git+ssh://bitbucket.example.com/libvcs/vcspull.git'
377+
378+ It also accepts revisions, e.g. branch, tag, ref:
379+
380+ >>> git_location = GitPipURL(
381+ ... url='git+https://github.com/vcs-python/libvcs.git@v0.10.0'
382+ ... )
383+
384+ >>> git_location
385+ GitPipURL(url=git+https://github.com/vcs-python/libvcs.git@v0.10.0,
386+ scheme=git+https,
387+ hostname=github.com,
388+ path=vcs-python/libvcs,
389+ suffix=.git,
390+ matcher=pip-url,
391+ rev=v0.10.0)
392+
393+ >>> git_location.path = 'libvcs/vcspull'
394+
395+ >>> git_location.to_url()
396+ 'git+https://github.com/libvcs/vcspull.git@v0.10.0'
397+ """
398+ url = super ().to_url ()
399+
400+ if self .rev :
401+ url = f"{ url } @{ self .rev } "
402+
403+ return url
404+
405+
406+ @dataclasses .dataclass (repr = False )
407+ class GitURL (GitPipURL , GitBaseURL , URLProtocol , SkipDefaultFieldsReprMixin ):
408+ """Batteries included URL Parser. Supports git(1) and pip URLs."""
409+
349410 matchers = MatcherRegistry = MatcherRegistry (
350411 _matchers = {m .label : m for m in [* DEFAULT_MATCHERS , * PIP_DEFAULT_MATCHERS ]}
351412 )
0 commit comments