2 var test = require('tap').test
4 var npm = require('../../lib/npm.js')
5 var common = require('../common-tap.js')
7 var normalizeGitUrl = require('normalize-git-url')
11 * Note: This is here because `normalizeGitUrl` is usually called
12 * before getResolved is, and receives *that* URL.
14 function tryGetResolved(uri, treeish) {
15 return getResolved(normalizeGitUrl(uri).url, treeish)
18 test('setup', function (t) {
20 registry: common.registry,
23 npm.load(opts, function (er) {
24 t.ifError(er, 'npm loaded without error')
25 getResolved = require('../../lib/cache/add-remote-git.js').getResolved
30 test('add-remote-git#get-resolved git: passthru', function (t) {
31 verify('git:github.com/foo/repo')
32 verify('git:github.com/foo/repo.git')
33 verify('git://github.com/foo/repo#decadacefadabade')
34 verify('git://github.com/foo/repo.git#decadacefadabade')
36 function verify (uri) {
38 tryGetResolved(uri, 'decadacefadabade'),
39 'git://github.com/foo/repo.git#decadacefadabade',
40 uri + ' normalized to canonical form git://github.com/foo/repo.git#decadacefadabade'
46 test('add-remote-git#get-resolved SSH', function (t) {
47 t.comment('tests for https://github.com/npm/npm/issues/7961')
48 verify('git@github.com:foo/repo')
49 verify('git@github.com:foo/repo#master')
50 verify('git+ssh://git@github.com/foo/repo#master')
51 verify('git+ssh://git@github.com/foo/repo#decadacefadabade')
53 function verify (uri) {
55 tryGetResolved(uri, 'decadacefadabade'),
56 'git+ssh://git@github.com/foo/repo.git#decadacefadabade',
57 uri + ' normalized to canonical form git+ssh://git@github.com/foo/repo.git#decadacefadabade'
63 test('add-remote-git#get-resolved HTTPS', function (t) {
64 verify('https://github.com/foo/repo')
65 verify('https://github.com/foo/repo#master')
66 verify('git+https://github.com/foo/repo.git#master')
67 verify('git+https://github.com/foo/repo#decadacefadabade')
69 // this is an invalid URL but we normalize it
70 // anyway. Users shouldn't use this in the future. See note
71 // below for how this affected non-hosted URLs.
72 // See https://github.com/npm/npm/issues/8881
73 verify('git+https://github.com:foo/repo.git#master')
75 function verify (uri) {
77 tryGetResolved(uri, 'decadacefadabade'),
78 'git+https://github.com/foo/repo.git#decadacefadabade',
79 uri + ' normalized to canonical form git+https://github.com/foo/repo.git#decadacefadabade'
85 test('add-remote-git#get-resolved edge cases', function (t) {
88 tryGetResolved('git+ssh://user@bananaboat.com:galbi/blah.git', 'decadacefadabade'),
89 'git+ssh://user@bananaboat.com:galbi/blah.git#decadacefadabade',
90 'don\'t break non-hosted scp-style locations'
94 tryGetResolved('git+ssh://bananaboat:galbi/blah', 'decadacefadabade'),
95 'git+ssh://bananaboat:galbi/blah#decadacefadabade',
96 'don\'t break non-hosted scp-style locations'
100 // When we were normalizing all git URIs, git+https: was being
101 // automatically converted to ssh:. Some users were relying
102 // on this funky behavior, so after removing the aggressive
103 // normalization from non-hosted URIs, we brought this back.
104 // See https://github.com/npm/npm/issues/8881
106 tryGetResolved('git+https://bananaboat:galbi/blah', 'decadacefadabade'),
107 'git+https://bananaboat/galbi/blah#decadacefadabade',
108 'don\'t break non-hosted scp-style locations'
112 tryGetResolved('git+ssh://git.bananaboat.net/foo', 'decadacefadabade'),
113 'git+ssh://git.bananaboat.net/foo#decadacefadabade',
114 'don\'t break non-hosted SSH URLs'
118 tryGetResolved('git+ssh://git.bananaboat.net:/foo', 'decadacefadabade'),
119 'git+ssh://git.bananaboat.net:/foo#decadacefadabade',
120 'don\'t break non-hosted SSH URLs'
124 tryGetResolved('git://gitbub.com/foo/bar.git', 'decadacefadabade'),
125 'git://gitbub.com/foo/bar.git#decadacefadabade',
126 'don\'t break non-hosted git: URLs'