|
|
@ -6,46 +6,6 @@ import type { getRemoteProviderMatcher } from '../remotes/remoteProviders'; |
|
|
|
const emptyStr = ''; |
|
|
|
|
|
|
|
const remoteRegex = /^(.*)\t(.*)\s\((.*)\)$/gm; |
|
|
|
const urlRegex = |
|
|
|
/^(?:(git:\/\/)(.*?)\/|(https?:\/\/)(?:.*?@)?(.*?)\/|git@(.*):|(ssh:\/\/)(?:.*@)?(.*?)(?::.*?)?(?:\/|(?=~))|(?:.*?@)(.*?):)(.*)$/; |
|
|
|
|
|
|
|
// Test git urls
|
|
|
|
/* |
|
|
|
http://host.xz/user/project.git
|
|
|
|
http://host.xz/path/to/repo.git
|
|
|
|
http://host.xz/path/to/repo.git/
|
|
|
|
http://username@host.xz/user/project.git
|
|
|
|
http://username:password@host.xz/user/project.git
|
|
|
|
https://host.xz/user/project.git
|
|
|
|
https://host.xz/path/to/repo.git
|
|
|
|
https://host.xz/path/to/repo.git/
|
|
|
|
https://username@host.xz/user/project.git
|
|
|
|
https://username:password@host.xz/user/project.git
|
|
|
|
|
|
|
|
git@host.xz:user/project.git |
|
|
|
git://host.xz/path/to/repo.git/
|
|
|
|
git://host.xz/~user/path/to/repo.git/
|
|
|
|
|
|
|
|
ssh://host.xz/project.git
|
|
|
|
ssh://host.xz/path/to/repo.git
|
|
|
|
ssh://host.xz/path/to/repo.git/
|
|
|
|
ssh://host.xz:~project.git
|
|
|
|
ssh://host.xz:port/path/to/repo.git/
|
|
|
|
ssh://user@host.xz/project.git
|
|
|
|
ssh://user@host.xz/path/to/repo.git
|
|
|
|
ssh://user@host.xz/path/to/repo.git/
|
|
|
|
ssh://user@host.xz:port/path/to/repo.git/
|
|
|
|
ssh://user:password@host.xz/project.git
|
|
|
|
ssh://user:password@host.xz/path/to/repo.git
|
|
|
|
ssh://user:password@host.xz/path/to/repo.git/
|
|
|
|
|
|
|
|
user@host.xz:project.git |
|
|
|
user@host.xz:path/to/repo.git |
|
|
|
user@host.xz:/path/to/repo.git/ |
|
|
|
user:password@host.xz:project.git |
|
|
|
user:password@host.xz:/path/to/repo.git |
|
|
|
user:password@host.xz:/path/to/repo.git/ |
|
|
|
*/ |
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
|
|
export class GitRemoteParser { |
|
|
@ -81,7 +41,7 @@ export class GitRemoteParser { |
|
|
|
// Stops excessive memory usage -- https://bugs.chromium.org/p/v8/issues/detail?id=2869
|
|
|
|
url = ` ${url}`.substr(1); |
|
|
|
|
|
|
|
[scheme, domain, path] = this.parseGitUrl(url); |
|
|
|
[scheme, domain, path] = parseGitRemoteUrl(url); |
|
|
|
|
|
|
|
uniqueness = `${domain ? `${domain}/` : ''}${path}`; |
|
|
|
remote = groups[uniqueness]; |
|
|
@ -110,15 +70,55 @@ export class GitRemoteParser { |
|
|
|
|
|
|
|
return remotes; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static parseGitUrl(url: string): [string, string, string] { |
|
|
|
const match = urlRegex.exec(url); |
|
|
|
if (match == null) return [emptyStr, emptyStr, url]; |
|
|
|
// Test git urls
|
|
|
|
/* |
|
|
|
http://host.xz/user/project.git
|
|
|
|
http://host.xz/path/to/repo.git
|
|
|
|
http://host.xz/path/to/repo.git/
|
|
|
|
http://username@host.xz/user/project.git
|
|
|
|
http://username:password@host.xz/user/project.git
|
|
|
|
https://host.xz/user/project.git
|
|
|
|
https://host.xz/path/to/repo.git
|
|
|
|
https://host.xz/path/to/repo.git/
|
|
|
|
https://username@host.xz/user/project.git
|
|
|
|
https://username:password@host.xz/user/project.git
|
|
|
|
|
|
|
|
return [ |
|
|
|
match[1] || match[3] || match[6], |
|
|
|
match[2] || match[4] || match[5] || match[7] || match[8], |
|
|
|
match[9].replace(/\.git\/?$/, emptyStr), |
|
|
|
]; |
|
|
|
} |
|
|
|
git@host.xz:user/project.git |
|
|
|
git://host.xz/path/to/repo.git/
|
|
|
|
git://host.xz/~user/path/to/repo.git/
|
|
|
|
|
|
|
|
ssh://host.xz/project.git
|
|
|
|
ssh://host.xz/path/to/repo.git
|
|
|
|
ssh://host.xz/path/to/repo.git/
|
|
|
|
ssh://host.xz:~project.git
|
|
|
|
ssh://host.xz:port/path/to/repo.git/
|
|
|
|
ssh://user@host.xz/project.git
|
|
|
|
ssh://user@host.xz/path/to/repo.git
|
|
|
|
ssh://user@host.xz/path/to/repo.git/
|
|
|
|
ssh://user@host.xz:port/path/to/repo.git/
|
|
|
|
ssh://user:password@host.xz/project.git
|
|
|
|
ssh://user:password@host.xz/path/to/repo.git
|
|
|
|
ssh://user:password@host.xz/path/to/repo.git/
|
|
|
|
|
|
|
|
user@host.xz:project.git |
|
|
|
user@host.xz:path/to/repo.git |
|
|
|
user@host.xz:/path/to/repo.git/ |
|
|
|
user:password@host.xz:project.git |
|
|
|
user:password@host.xz:/path/to/repo.git |
|
|
|
user:password@host.xz:/path/to/repo.git/ |
|
|
|
*/ |
|
|
|
const urlRegex = |
|
|
|
/^(?:(git:\/\/)(.*?)\/|(https?:\/\/)(?:.*?@)?(.*?)\/|git@(.*):|(ssh:\/\/)(?:.*@)?(.*?)(?::.*?)?(?:\/|(?=~))|(?:.*?@)(.*?):)(.*)$/; |
|
|
|
|
|
|
|
export function parseGitRemoteUrl(url: string): [scheme: string, domain: string, path: string] { |
|
|
|
const match = urlRegex.exec(url); |
|
|
|
if (match == null) return [emptyStr, emptyStr, url]; |
|
|
|
|
|
|
|
return [ |
|
|
|
match[1] || match[3] || match[6], |
|
|
|
match[2] || match[4] || match[5] || match[7] || match[8], |
|
|
|
match[9].replace(/\.git\/?$/, emptyStr), |
|
|
|
]; |
|
|
|
} |