Skip to content

Commit 675a3c8

Browse files
committed
bugfix: Preserve https protocol when working with git
This prevents changing URLs from https and git+https into git+ssh, but keeps the fall-back to git+ssh when the protocol is not specified. Supersedes #5256 Fixes #4305 Fixes #2610 Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
1 parent 06510a8 commit 675a3c8

File tree

9 files changed

+39
-38
lines changed

9 files changed

+39
-38
lines changed

tap-snapshots/test/lib/commands/ls.js.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ print-deduped-symlinks@1.0.0 {CWD}/prefix
565565

566566
exports[`test/lib/commands/ls.js TAP ls resolved points to git ref > should output tree containing git refs 1`] = `
567567
test-npm-ls@1.0.0 {CWD}/prefix
568-
\`-- abbrev@1.1.1 (git+ssh://git@github.com/isaacs/abbrev-js.git#b8f3a2fc0c3bb8ffd8b0d0072cc6b5a3667e963c)
568+
\`-- abbrev@1.1.1 (git+https://github.com/isaacs/abbrev-js.git#b8f3a2fc0c3bb8ffd8b0d0072cc6b5a3667e963c)
569569
`
570570

571571
exports[`test/lib/commands/ls.js TAP ls unmet optional dep > should output tree with empty entry for missing optional deps 1`] = `

test/lib/commands/ls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4225,7 +4225,7 @@ t.test('ls --json', async t => {
42254225
abbrev: {
42264226
version: '1.1.1',
42274227
overridden: false,
4228-
resolved: 'git+ssh://git@github.com/isaacs/abbrev-js.git#b8f3a2fc0c3bb8ffd8b0d0072cc6b5a3667e963c',
4228+
resolved: 'git+https://github.com/isaacs/abbrev-js.git#b8f3a2fc0c3bb8ffd8b0d0072cc6b5a3667e963c',
42294229
},
42304230
},
42314231
},

workspaces/arborist/lib/arborist/reify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ module.exports = cls => class Reifier extends cls {
13221322
// save the git+https url if it has auth; otherwise, shortcut
13231323
const h = req.hosted
13241324
const opt = { noCommittish: false }
1325-
if (h.https && h.auth) {
1325+
if (h.https && (h.auth || h.default === 'https')) {
13261326
newSpec = `git+${h.https(opt)}`
13271327
} else {
13281328
newSpec = h.shortcut(opt)

workspaces/arborist/lib/consistent-resolve.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const consistentResolve = (resolved, fromPath, toPath, relPaths = false) => {
2626
return `file:${fetchSpec}`
2727
}
2828
if (hosted) {
29-
return `git+${hosted.auth ? hosted.https(hostedOpt) : hosted.sshurl(hostedOpt)}`
29+
return `git+${(hosted.auth || hosted.default === "https") ? hosted.https(hostedOpt) : hosted.sshurl(hostedOpt)}`
3030
}
3131
if (type === 'git') {
3232
return saveSpec

workspaces/arborist/tap-snapshots/test/arborist/load-actual.js.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ ArboristNode {
16271627
"name": "full-git-url",
16281628
"packageName": "abbrev",
16291629
"path": "install-types/node_modules/full-git-url",
1630-
"resolved": "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
1630+
"resolved": "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
16311631
"version": "1.1.1",
16321632
},
16331633
"ghshort" => ArboristNode {

workspaces/arborist/tap-snapshots/test/arborist/load-virtual.js.test.cjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13531,7 +13531,7 @@ ArboristNode {
1353113531
"location": "node_modules/full-git-url",
1353213532
"name": "full-git-url",
1353313533
"path": "{CWD}/test/fixtures/install-types/node_modules/full-git-url",
13534-
"resolved": "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
13534+
"resolved": "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
1353513535
},
1353613536
"ghshort" => ArboristNode {
1353713537
"edgesIn": Set {
@@ -14220,7 +14220,7 @@ ArboristNode {
1422014220
"location": "node_modules/full-git-url",
1422114221
"name": "full-git-url",
1422214222
"path": "{CWD}/test/fixtures/install-types/node_modules/full-git-url",
14223-
"resolved": "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
14223+
"resolved": "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
1422414224
},
1422514225
"ghshort" => ArboristNode {
1422614226
"edgesIn": Set {
@@ -14909,7 +14909,7 @@ ArboristNode {
1490914909
"location": "node_modules/full-git-url",
1491014910
"name": "full-git-url",
1491114911
"path": "{CWD}/test/arborist/tap-testdir-load-virtual-load-from-npm-shrinkwrap.json/node_modules/full-git-url",
14912-
"resolved": "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
14912+
"resolved": "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
1491314913
},
1491414914
"ghshort" => ArboristNode {
1491514915
"edgesIn": Set {
@@ -15562,7 +15562,7 @@ ArboristNode {
1556215562
"location": "node_modules/full-git-url",
1556315563
"name": "full-git-url",
1556415564
"path": "{CWD}/test/fixtures/install-types-sw-only/node_modules/full-git-url",
15565-
"resolved": "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
15565+
"resolved": "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
1556615566
},
1556715567
"ghshort" => ArboristNode {
1556815568
"location": "node_modules/ghshort",

workspaces/arborist/tap-snapshots/test/shrinkwrap.js.test.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ Object {
941941
"version": "1.0.0",
942942
},
943943
"node_modules/full-git-url": Object {
944-
"resolved": "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
944+
"resolved": "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
945945
},
946946
"node_modules/ghshort": Object {
947947
"resolved": "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
@@ -1686,7 +1686,7 @@ Object {
16861686
"node_modules/full-git-url": Object {
16871687
"license": "ISC",
16881688
"name": "abbrev",
1689-
"resolved": "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
1689+
"resolved": "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
16901690
"version": "1.1.1",
16911691
},
16921692
"node_modules/ghshort": Object {
@@ -9925,7 +9925,7 @@ Object {
99259925

99269926
exports[`test/shrinkwrap.js TAP look up from locks and such lockfile > full git 1`] = `
99279927
Object {
9928-
"resolved": "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
9928+
"resolved": "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb",
99299929
}
99309930
`
99319931

workspaces/arborist/tap-snapshots/test/yarn-lock.js.test.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fs.realpath@^1.0.0:
122122
123123
"full-git-url@git+https://github.com/isaacs/abbrev-js.git":
124124
version "1.1.1"
125-
resolved "git+ssh://git@github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb"
125+
resolved "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb"
126126
127127
"ghshort@github:isaacs/abbrev-js":
128128
version "1.1.1"

workspaces/arborist/test/consistent-resolve.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,36 @@ t.test('file and directories made consistent if toPath not set', t => {
5555
})
5656

5757
t.test('consistent hosted git info urls', t => {
58-
const expect = 'git+ssh://git@github.com/a/b.git'
58+
const expectSsh = 'git+ssh://git@github.com/a/b.git'
59+
const expectHttps = 'git+https://github.com/a/b.git'
5960
const expectAuth = 'git+https://user:pass@github.com/a/b.git'
60-
t.equal(cr('a/b'), expect)
61-
t.equal(cr('github:a/b'), expect)
62-
t.equal(cr('git+https://github.com/a/b'), expect)
63-
t.equal(cr('git://github.com/a/b'), expect)
64-
t.equal(cr('git+ssh://git@github.com/a/b'), expect)
65-
t.equal(cr('git+https://github.com/a/b.git'), expect)
66-
t.equal(cr('git://github.com/a/b.git'), expect)
67-
t.equal(cr('git+ssh://git@github.com/a/b.git'), expect)
61+
t.equal(cr('a/b'), expectSsh)
62+
t.equal(cr('github:a/b'), expectSsh)
63+
t.equal(cr('git+https://github.com/a/b'), expectHttps)
64+
t.equal(cr('git://github.com/a/b'), expectSsh)
65+
t.equal(cr('git+ssh://git@github.com/a/b'), expectSsh)
66+
t.equal(cr('git+https://github.com/a/b.git'), expectHttps)
67+
t.equal(cr('git://github.com/a/b.git'), expectSsh)
68+
t.equal(cr('git+ssh://git@github.com/a/b.git'), expectSsh)
6869
t.equal(cr('git+https://user:pass@github.com/a/b.git'), expectAuth)
6970

7071
const hash = '#0000000000000000000000000000000000000000'
71-
t.equal(cr('a/b' + hash), expect + hash)
72-
t.equal(cr('github:a/b' + hash), expect + hash)
73-
t.equal(cr('git+https://github.com/a/b' + hash), expect + hash)
74-
t.equal(cr('git://github.com/a/b' + hash), expect + hash)
75-
t.equal(cr('git+ssh://git@github.com/a/b' + hash), expect + hash)
76-
t.equal(cr('git+https://github.com/a/b.git' + hash), expect + hash)
77-
t.equal(cr('git://github.com/a/b.git' + hash), expect + hash)
78-
t.equal(cr('git+ssh://git@github.com/a/b.git' + hash), expect + hash)
79-
t.equal(cr('xyz@a/b' + hash), expect + hash)
80-
t.equal(cr('xyz@github:a/b' + hash), expect + hash)
81-
t.equal(cr('xyz@git+https://github.com/a/b' + hash), expect + hash)
82-
t.equal(cr('xyz@git://github.com/a/b' + hash), expect + hash)
83-
t.equal(cr('xyz@git+ssh://git@github.com/a/b' + hash), expect + hash)
84-
t.equal(cr('xyz@git+https://github.com/a/b.git' + hash), expect + hash)
85-
t.equal(cr('xyz@git://github.com/a/b.git' + hash), expect + hash)
86-
t.equal(cr('xyz@git+ssh://git@github.com/a/b.git' + hash), expect + hash)
72+
t.equal(cr('a/b' + hash), expectSsh + hash)
73+
t.equal(cr('github:a/b' + hash), expectSsh + hash)
74+
t.equal(cr('git+https://github.com/a/b' + hash), expectHttps + hash)
75+
t.equal(cr('git://github.com/a/b' + hash), expectSsh + hash)
76+
t.equal(cr('git+ssh://git@github.com/a/b' + hash), expectSsh + hash)
77+
t.equal(cr('git+https://github.com/a/b.git' + hash), expectHttps + hash)
78+
t.equal(cr('git://github.com/a/b.git' + hash), expectSsh + hash)
79+
t.equal(cr('git+ssh://git@github.com/a/b.git' + hash), expectSsh + hash)
80+
t.equal(cr('xyz@a/b' + hash), expectSsh + hash)
81+
t.equal(cr('xyz@github:a/b' + hash), expectSsh + hash)
82+
t.equal(cr('xyz@git+https://github.com/a/b' + hash), expectHttps + hash)
83+
t.equal(cr('xyz@git://github.com/a/b' + hash), expectSsh + hash)
84+
t.equal(cr('xyz@git+ssh://git@github.com/a/b' + hash), expectSsh + hash)
85+
t.equal(cr('xyz@git+https://github.com/a/b.git' + hash), expectHttps + hash)
86+
t.equal(cr('xyz@git://github.com/a/b.git' + hash), expectSsh + hash)
87+
t.equal(cr('xyz@git+ssh://git@github.com/a/b.git' + hash), expectSsh + hash)
8788
t.end()
8889
})
8990

0 commit comments

Comments
 (0)