mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 10:54:13 +00:00

PR-URL: https://github.com/nodejs/io.js/pull/2112 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
31 lines
783 B
JavaScript
31 lines
783 B
JavaScript
var url = require('url')
|
|
|
|
module.exports = function normalize (u) {
|
|
var parsed = url.parse(u, true)
|
|
|
|
// git is so tricky!
|
|
// if the path is like ssh://foo:22/some/path then it works, but
|
|
// it needs the ssh://
|
|
// If the path is like ssh://foo:some/path then it works, but
|
|
// only if you remove the ssh://
|
|
if (parsed.protocol) {
|
|
parsed.protocol = parsed.protocol.replace(/^git\+/, '')
|
|
}
|
|
|
|
// figure out what we should check out.
|
|
var checkout = parsed.hash && parsed.hash.substr(1) || 'master'
|
|
parsed.hash = ''
|
|
|
|
var returnedUrl
|
|
if (parsed.pathname.match(/\/?:/)) {
|
|
returnedUrl = u.replace(/^(?:git\+)?ssh:\/\//, '').replace(/#[^#]*$/, '')
|
|
} else {
|
|
returnedUrl = url.format(parsed)
|
|
}
|
|
|
|
return {
|
|
url: returnedUrl,
|
|
branch: checkout
|
|
}
|
|
}
|