Git URL Parser - libvcs.url.git¶
Detect, parse, and change git URLs using libvcs’s URL parser for git(1). It builds on top of the
VCS-friendly URL parser framework.
Detect, parse, and validate git URLs.
Detect:
GitURL.is_valid()Parse:
compare to
urllib.parse.ParseResultCompatibility focused:
GitURL: Will work withgit(1)as well aspip(1)style URLsOutput
git(1)URL:GitURL.to_url()
Strict
git(1)compatibility:GitBaseURL.Output
git(1)URL:GitBaseURL.to_url()
-
libvcs.url.git.DEFAULT_RULES: list[Rule] = [Rule(label=core-git-https, description=Vanilla git pattern, URL ending with optional .git suffix, pattern=re.compile('\n ^\n (?P<scheme>\n (\n http|https\n )\n )\n\n ://\n \n ((?P<user>[^/:@]+)@)?\n\n \n (?P<hostname>([^/:@]+))\n (:(?P<port>\\d{1,5}))?\n , re.VERBOSE), defaults={}, is_explicit=True), Rule(label=core-git-scp, description=Vanilla scp(1) / ssh(1) type URL, pattern=re.compile("\n ^(?P<scheme>ssh)?\n \n ((?P<user>[^/:@]+)@)?\n\n \n # Server, e.g. 'github.com'.\n (?P<hostname>([^/:]+))\n (?P<separator>:)\n # The server-side path. e.g. 'use, re.VERBOSE), defaults={'username': 'git'}, is_explicit=True)]¶
Core regular expressions. These are patterns understood by
git(1)See also: https://git-scm.com/docs/git-clone#URLS
-
libvcs.url.git.AWS_CODE_COMMIT_DEFAULT_RULES: list[Rule] = [Rule(label=aws-code-commit-https, description=AWS CodeCommit HTTPS-style, pattern=re.compile("\n https://git-codecommit\\.\n ((?P<region>[^/]+)\\.)\n # Server, e.g. 'github.com'.\n (?P<hostname>([^/:]+))\n (?P<separator>:)?\n # The server-side path. e, re.VERBOSE), defaults={}, is_explicit=True), Rule(label=aws-code-commit-ssh, description=AWS CodeCommit SSH-style, pattern=re.compile("\n ssh://git-codecommit\\.\n ((?P<region>[^/]+)\\.)\n # Server, e.g. 'github.com'.\n (?P<hostname>([^/:]+))\n (?P<separator>:)?\n # The server-side path. e.g, re.VERBOSE), defaults={}, is_explicit=True), Rule(label=aws-code-commit-https-grc, description=AWS CodeCommit git repository, pattern=re.compile('\n codecommit://\n \n (?P<hostname>([^/:@]+))\n (:(?P<port>\\d{1,5}))?\n (?P<separator>[:,/])?\n (?P<path>\n (\\w[^:.@]*) # cut the path at . to negate .git, @, re.VERBOSE), defaults={}, is_explicit=True), Rule(label=aws-code-commit-https-grc-with-region, description=AWS CodeCommit git repository with region, pattern=re.compile('\n codecommit::\n (?P<region>[^/]+)\n ://\n \n (?P<hostname>([^/:@]+))\n (:(?P<port>\\d{1,5}))?\n (?P<separator>[:,/])?\n (?P<path>\n (\\w, re.VERBOSE), defaults={}, is_explicit=True)]¶
AWS CodeCommit-style git URLs.
Examples of CodeCommit-style git URLs (via AWS):
codecommit://MyDemoRepo codecommit://`CodeCommitProfile`@MyDemoRepo codecommit::ap-northeast-1://MyDemoRepo
Notes
-
libvcs.url.git.PIP_DEFAULT_RULES: list[Rule] = [Rule(label=pip-url, description=pip-style git URL, pattern=re.compile('\n \n (?P<scheme>\n (\n git\\+ssh|\n git\\+https|\n git\\+http|\n git\\+file\n )\n )\n\n ://\n \n ((?P<user>[^/:@]+)@)?\n\n , re.VERBOSE), defaults={}, is_explicit=True), Rule(label=pip-scp-url, description=pip-style git ssh/scp URL, pattern=re.compile("\n \n (?P<scheme>\n (\n git\\+ssh|\n git\\+file\n )\n )\n\n \n ((?P<user>[^/:@]+)@)?\n\n \n # Server, e.g. 'github.com'.\n (?P<hostname>([^, re.VERBOSE), defaults={}, is_explicit=True), Rule(label=pip-file-url, description=pip-style git+file:// URL, pattern=re.compile('\n (?P<scheme>git\\+file)://\n (?P<path>[^@]*)\n \n (@(?P<rev>.*))\n?\n ', re.VERBOSE), defaults={}, is_explicit=True)]¶
pip-style git URLs.
Examples of PIP-style git URLs (via pip.pypa.io):
MyProject @ git+ssh://git.example.com/MyProject MyProject @ git+file:///home/user/projects/MyProject MyProject @ git+https://git.example.com/MyProject
Refs (via pip.pypa.io):
MyProject @ git+https://git.example.com/MyProject.git@master MyProject @ git+https://git.example.com/MyProject.git@v1.0 MyProject @ git+https://git.example.com/MyProject.git@da39a3ee5e6b4b0d3255bfef95601890afd80709 MyProject @ git+https://git.example.com/MyProject.git@refs/pull/123/head
Notes
NPM-style git URLs.
Git URL pattern (from docs.npmjs.com):
<protocol>://[<user>[:<password>]@]<hostname>[:<port>][:][/]<path>[#<commit-ish> | #semver:<semver>]
Examples of NPM-style git URLs (from docs.npmjs.com):
ssh://git@github.com:npm/cli.git#v1.0.27 git+ssh://git@github.com:npm/cli#semver:^5.0 git+https://isaacs@github.com/npm/cli.git git://github.com/npm/cli.git#v1.0.27
Notes
-
class libvcs.url.git.GitBaseURL¶
Bases:
URLProtocol,SkipDefaultFieldsReprMixinGit repository location. Parses URLs on initialization.
Examples
>>> GitBaseURL(url='https://github.com/vcs-python/libvcs.git') GitBaseURL(url=https://github.com/vcs-python/libvcs.git, scheme=https, hostname=github.com, path=vcs-python/libvcs, suffix=.git, rule=core-git-https)
>>> myrepo = GitBaseURL(url='https://github.com/myproject/myrepo.git')
>>> myrepo.hostname 'github.com'
>>> myrepo.path 'myproject/myrepo'
>>> GitBaseURL(url='[email protected]:vcs-python/libvcs.git') GitBaseURL([email protected]:vcs-python/libvcs.git, user=git, hostname=github.com, path=vcs-python/libvcs, suffix=.git, rule=core-git-scp)
Compatibility checking:
GitBaseURL.is_valid()URLs compatible with
git(1):GitBaseURL.to_url()
-
class libvcs.url.git.GitAWSCodeCommitURL¶
Bases:
GitBaseURL,URLProtocol,SkipDefaultFieldsReprMixinSupports AWS CodeCommit git URLs.
-
class libvcs.url.git.GitPipURL¶
Bases:
GitBaseURL,URLProtocol,SkipDefaultFieldsReprMixinSupports pip git URLs.
-
class libvcs.url.git.GitURL¶
Bases:
GitAWSCodeCommitURL,GitPipURL,GitBaseURL,URLProtocol,SkipDefaultFieldsReprMixinBatteries included URL Parser. Supports git(1) and pip URLs.
Ancestors (MRO) This URL parser inherits methods and attributes from the following parsers: