Skip to content

Commit a200ae9

Browse files
committed
bugfix: do not switch to git+ssh for https repository links
When the URL explicitly contains https, do not try to switch to ssh. This change is necessary for [npm][3] to retain the protocol, please see the link and the referenced issues [here][1] and [here][2] reporting problems when using ssh instead of requested https. [1]: npm/cli#2610 [2]: npm/cli#4305 [3]: npm/cli#8703 Signed-off-by: Oldřich Jedlička <[email protected]>
1 parent 5a3261c commit a200ae9

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

lib/git.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const hashre = /^[a-f0-9]{40}$/
1919
// otherwise, prefer ssh if available (more secure).
2020
// We have to add the git+ back because npa suppresses it.
2121
const repoUrl = (h, opts) =>
22-
h.sshurl && !(h.https && h.auth) && addGitPlus(h.sshurl(opts)) ||
22+
h.sshurl && !(h.https && (h.auth || h.default === 'https')) && addGitPlus(h.sshurl(opts)) ||
2323
h.https && addGitPlus(h.https(opts))
2424

2525
// add git+ to the url, but only one time.

lib/util/add-git-sha.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const addGitSha = (spec, sha) => {
33
if (spec.hosted) {
44
const h = spec.hosted
55
const opt = { noCommittish: true }
6-
const base = h.https && h.auth ? h.https(opt) : h.shortcut(opt)
6+
const base = h.https && (h.auth || h.default === 'https') ? h.https(opt) : h.shortcut(opt)
77

88
return `${base}#${sha}`
99
} else {

test/git.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,14 @@ t.test('repoUrl function', { skip: isWindows && 'posix only' }, async t => {
670670
const { hosted: ssh } = npa(`git+ssh://[email protected]/${proj}`)
671671
const { hosted: git } = npa(`git://github.com/${proj}`)
672672
const { repoUrl } = GitFetcher
673-
const expectNoAuth = `git+ssh://[email protected]/${proj}`
673+
const expectNoAuthSsh = `git+ssh://[email protected]/${proj}`
674+
const expectNoAuthHttps = `git+https://github.com/${proj}`
674675
const expectAuth = `git+https://user:[email protected]/${proj}`
675-
t.match(repoUrl(shortcut), expectNoAuth)
676+
t.match(repoUrl(shortcut), expectNoAuthSsh)
676677
t.match(repoUrl(hasAuth), expectAuth)
677-
t.match(repoUrl(noAuth), expectNoAuth)
678-
t.match(repoUrl(ssh), expectNoAuth)
679-
t.match(repoUrl(git), expectNoAuth)
678+
t.match(repoUrl(noAuth), expectNoAuthHttps)
679+
t.match(repoUrl(ssh), expectNoAuthSsh)
680+
t.match(repoUrl(git), expectNoAuthSsh)
680681
})
681682

682683
t.test('handle it when prepared git deps depend on each other', { skip: isWindows && 'posix only' },

test/util/add-git-sha.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const cases = [
2828
'sha',
2929
'https://[email protected]/user/repo.git#sha'],
3030
// github https no auth
31-
['git+https://github.com/user/repo', 'sha', 'github:user/repo#sha'],
32-
['git+https://github.com/user/repo#othersha', 'sha', 'github:user/repo#sha'],
33-
['git+https://github.com/user/repo#othersha#otherothersha', 'sha', 'github:user/repo#sha'],
31+
['git+https://github.com/user/repo', 'sha', 'https://github.com/user/repo.git#sha'],
32+
['git+https://github.com/user/repo#othersha', 'sha', 'https://github.com/user/repo.git#sha'],
33+
['git+https://github.com/user/repo#othersha#otherothersha', 'sha', 'https://github.com/user/repo.git#sha'],
3434
// github ssh
3535
['git+ssh://[email protected]/user/repo', 'sha', 'github:user/repo#sha'],
3636
['git+ssh://[email protected]/user/repo#othersha', 'sha', 'github:user/repo#sha'],

0 commit comments

Comments
 (0)