1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
'use strict'
var test = require('tap').test
var npm = require('../../lib/npm.js')
var common = require('../common-tap.js')
var npa = require('npm-package-arg')
var getResolved = null
/**
* Note: This is here because `normalizeGitUrl` is usually called
* before getResolved is, and receives *that* URL.
*/
function tryGetResolved (uri, treeish) {
return getResolved(npa(uri), uri, treeish)
}
test('setup', function (t) {
var opts = {
registry: common.registry,
loglevel: 'silent'
}
npm.load(opts, function (er) {
t.ifError(er, 'npm loaded without error')
getResolved = require('../../lib/cache/add-remote-git.js').getResolved
t.end()
})
})
test('add-remote-git#get-resolved git: passthru', function (t) {
verify('git:github.com/foo/repo')
verify('git:github.com/foo/repo.git')
verify('git://github.com/foo/repo#decadacefadabade')
verify('git://github.com/foo/repo.git#decadacefadabade')
function verify (uri) {
t.equal(
tryGetResolved(uri, 'decadacefadabade'),
'git://github.com/foo/repo.git#decadacefadabade',
uri + ' normalized to canonical form git://github.com/foo/repo.git#decadacefadabade'
)
}
t.end()
})
test('add-remote-git#get-resolved SSH', function (t) {
t.comment('tests for https://github.com/npm/npm/issues/7961')
verify('git+ssh://git@github.com:foo/repo')
verify('git+ssh://git@github.com:foo/repo#master')
verify('git+ssh://git@github.com/foo/repo#master')
verify('git+ssh://git@github.com/foo/repo#decadacefadabade')
function verify (uri) {
t.equal(
tryGetResolved(uri, 'decadacefadabade'),
'git+ssh://git@github.com/foo/repo.git#decadacefadabade',
uri + ' normalized to canonical form git+ssh://git@github.com/foo/repo.git#decadacefadabade'
)
}
t.end()
})
test('add-remote-git#get-resolved HTTPS', function (t) {
verify('https://github.com/foo/repo')
verify('https://github.com/foo/repo#master')
verify('git+https://github.com/foo/repo.git#master')
verify('git+https://github.com/foo/repo#decadacefadabade')
// DEPRECATED
// this is an invalid URL but we normalize it
// anyway. Users shouldn't use this in the future. See note
// below for how this affected non-hosted URLs.
// See https://github.com/npm/npm/issues/8881
verify('git+https://github.com:foo/repo.git#master')
function verify (uri) {
t.equal(
tryGetResolved(uri, 'decadacefadabade'),
'git+https://github.com/foo/repo.git#decadacefadabade',
uri + ' normalized to canonical form git+https://github.com/foo/repo.git#decadacefadabade'
)
}
t.end()
})
test('add-remote-git#get-resolved edge cases', function (t) {
t.equal(
tryGetResolved('git+ssh://user@bananaboat.com:galbi/blah.git', 'decadacefadabade'),
'git+ssh://user@bananaboat.com:galbi/blah.git#decadacefadabade',
'don\'t break non-hosted scp-style locations'
)
/*
t.equal(
tryGetResolved('git+ssh://bananaboat:galbi/blah', 'decadacefadabade'),
'git+ssh://bananaboat:galbi/blah#decadacefadabade',
'don\'t break non-hosted scp-style locations'
)
// DEPRECATED
// When we were normalizing all git URIs, git+https: was being
// automatically converted to ssh:. Some users were relying
// on this funky behavior, so after removing the aggressive
// normalization from non-hosted URIs, we brought this back.
// See https://github.com/npm/npm/issues/8881
t.equal(
tryGetResolved('git+https://bananaboat:galbi/blah', 'decadacefadabade'),
'git+https://bananaboat/galbi/blah#decadacefadabade',
'don\'t break non-hosted scp-style locations'
)
t.equal(
tryGetResolved('git+ssh://git.bananaboat.net/foo', 'decadacefadabade'),
'git+ssh://git.bananaboat.net/foo#decadacefadabade',
'don\'t break non-hosted SSH URLs'
)
t.equal(
tryGetResolved('git+ssh://git.bananaboat.net:/foo', 'decadacefadabade'),
'git+ssh://git.bananaboat.net:/foo#decadacefadabade',
'don\'t break non-hosted SSH URLs'
)
t.equal(
tryGetResolved('git://gitbub.com/foo/bar.git', 'decadacefadabade'),
'git://gitbub.com/foo/bar.git#decadacefadabade',
'don\'t break non-hosted git: URLs'
)
*/
t.end()
})
|