"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/normalize-git-url/normalize-git-url.js" (8 Mar 2017, 1175 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 }