summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/hosted-git-info/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/hosted-git-info/index.js')
-rw-r--r--deps/npm/node_modules/hosted-git-info/index.js56
1 files changed, 31 insertions, 25 deletions
diff --git a/deps/npm/node_modules/hosted-git-info/index.js b/deps/npm/node_modules/hosted-git-info/index.js
index 453ce87d38..a3fc25b839 100644
--- a/deps/npm/node_modules/hosted-git-info/index.js
+++ b/deps/npm/node_modules/hosted-git-info/index.js
@@ -23,37 +23,43 @@ var authProtocols = {
'git+http:': true
}
-module.exports.fromUrl = function (giturl) {
+module.exports.fromUrl = function (giturl, opts) {
if (giturl == null || giturl === '') return
var url = fixupUnqualifiedGist(
isGitHubShorthand(giturl) ? 'github:' + giturl : giturl
)
var parsed = parseGitUrl(url)
+ var shortcutMatch = url.match(new RegExp('^([^:]+):(?:(?:[^@:]+(?:[^@]+)?@)?([^/]*))[/](.+?)(?:[.]git)?($|#)'))
var matches = Object.keys(gitHosts).map(function (gitHostName) {
- var gitHostInfo = gitHosts[gitHostName]
- var auth = null
- if (parsed.auth && authProtocols[parsed.protocol]) {
- auth = decodeURIComponent(parsed.auth)
+ try {
+ var gitHostInfo = gitHosts[gitHostName]
+ var auth = null
+ if (parsed.auth && authProtocols[parsed.protocol]) {
+ auth = decodeURIComponent(parsed.auth)
+ }
+ var committish = parsed.hash ? decodeURIComponent(parsed.hash.substr(1)) : null
+ var user = null
+ var project = null
+ var defaultRepresentation = null
+ if (shortcutMatch && shortcutMatch[1] === gitHostName) {
+ user = shortcutMatch[2] && decodeURIComponent(shortcutMatch[2])
+ project = decodeURIComponent(shortcutMatch[3])
+ defaultRepresentation = 'shortcut'
+ } else {
+ if (parsed.host !== gitHostInfo.domain) return
+ if (!gitHostInfo.protocols_re.test(parsed.protocol)) return
+ if (!parsed.path) return
+ var pathmatch = gitHostInfo.pathmatch
+ var matched = parsed.path.match(pathmatch)
+ if (!matched) return
+ if (matched[1] != null) user = decodeURIComponent(matched[1])
+ if (matched[2] != null) project = decodeURIComponent(matched[2])
+ defaultRepresentation = protocolToRepresentation(parsed.protocol)
+ }
+ return new GitHost(gitHostName, user, auth, project, committish, defaultRepresentation, opts)
+ } catch (ex) {
+ if (!(ex instanceof URIError)) throw ex
}
- var committish = parsed.hash ? decodeURIComponent(parsed.hash.substr(1)) : null
- var user = null
- var project = null
- var defaultRepresentation = null
- if (parsed.protocol === gitHostName + ':') {
- user = decodeURIComponent(parsed.host)
- project = parsed.path && decodeURIComponent(parsed.path.replace(/^[/](.*?)(?:[.]git)?$/, '$1'))
- defaultRepresentation = 'shortcut'
- } else {
- if (parsed.host !== gitHostInfo.domain) return
- if (!gitHostInfo.protocols_re.test(parsed.protocol)) return
- var pathmatch = gitHostInfo.pathmatch
- var matched = parsed.path.match(pathmatch)
- if (!matched) return
- if (matched[1] != null) user = decodeURIComponent(matched[1])
- if (matched[2] != null) project = decodeURIComponent(matched[2])
- defaultRepresentation = protocolToRepresentation(parsed.protocol)
- }
- return new GitHost(gitHostName, user, auth, project, committish, defaultRepresentation)
}).filter(function (gitHostInfo) { return gitHostInfo })
if (matches.length !== 1) return
return matches[0]
@@ -83,7 +89,7 @@ function fixupUnqualifiedGist (giturl) {
function parseGitUrl (giturl) {
if (typeof giturl !== 'string') giturl = '' + giturl
- var matched = giturl.match(/^([^@]+)@([^:]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/)
+ var matched = giturl.match(/^([^@]+)@([^:/]+):[/]?((?:[^/]+[/])?[^/]+?)(?:[.]git)?(#.*)?$/)
if (!matched) return url.parse(giturl)
return {
protocol: 'git+ssh:',