]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/normalize-git-url/normalize-git-url.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / normalize-git-url / normalize-git-url.js
1 var url = require('url')
2
3 module.exports = function normalize (u) {
4   var parsed = url.parse(u)
5   // If parsing actually alters the URL, it is almost certainly an
6   // scp-style URL, or an invalid one.
7   var altered = u !== url.format(parsed)
8
9   // git is so tricky!
10   // if the path is like ssh://foo:22/some/path then it works, but
11   // it needs the ssh://
12   // If the path is like ssh://foo:some/path then it works, but
13   // only if you remove the ssh://
14   if (parsed.protocol) {
15     parsed.protocol = parsed.protocol.replace(/^git\+/, '')
16   }
17
18   // figure out what we should check out.
19   var checkout = parsed.hash && parsed.hash.substr(1) || 'master'
20   parsed.hash = ''
21
22   var returnedUrl
23   if (altered) {
24     if (u.match(/^git\+https?/) && parsed.pathname.match(/\/?:[^0-9]/)) {
25       returnedUrl = u.replace(/^git\+(.*:[^:]+):(.*)/, '$1/$2')
26     } else if (u.match(/^git\+file/)) {
27       returnedUrl = u.replace(/^git\+/, '')
28     } else {
29       returnedUrl = u.replace(/^(?:git\+)?ssh:\/\//, '')
30     }
31     returnedUrl = returnedUrl.replace(/#[^#]*$/, '')
32   } else {
33     returnedUrl = url.format(parsed)
34   }
35
36   return {
37     url: returnedUrl,
38     branch: checkout
39   }
40 }