Skip to content

Commit 6d160c1

Browse files
authored
fix!: do not switch to git+ssh for https repository links (#434)
BREAKING CHANGE: git specs using the `https` or `git+https` protocol now resolve to `git+https` URLs instead of being switched to `git+ssh`. Shortcut specs (e.g. `github:user/repo`, `user/repo`) and `git+ssh`/`git://` specs are unchanged. 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 ## References Relates to npm/cli#8703 Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
1 parent 6c2555a commit 6d160c1

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

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,64}$/
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
@@ -673,13 +673,14 @@ t.test('repoUrl function', { skip: isWindows && 'posix only' }, async t => {
673673
const { hosted: ssh } = npa(`git+ssh://git@github.com/${proj}`)
674674
const { hosted: git } = npa(`git://github.com/${proj}`)
675675
const { repoUrl } = GitFetcher
676-
const expectNoAuth = `git+ssh://git@github.com/${proj}`
676+
const expectNoAuthSsh = `git+ssh://git@github.com/${proj}`
677+
const expectNoAuthHttps = `git+https://github.com/${proj}`
677678
const expectAuth = `git+https://user:pass@github.com/${proj}`
678-
t.match(repoUrl(shortcut), expectNoAuth)
679+
t.match(repoUrl(shortcut), expectNoAuthSsh)
679680
t.match(repoUrl(hasAuth), expectAuth)
680-
t.match(repoUrl(noAuth), expectNoAuth)
681-
t.match(repoUrl(ssh), expectNoAuth)
682-
t.match(repoUrl(git), expectNoAuth)
681+
t.match(repoUrl(noAuth), expectNoAuthHttps)
682+
t.match(repoUrl(ssh), expectNoAuthSsh)
683+
t.match(repoUrl(git), expectNoAuthSsh)
683684
})
684685

685686
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://git@github.com/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://git@github.com/user/repo', 'sha', 'github:user/repo#sha'],
3636
['git+ssh://git@github.com/user/repo#othersha', 'sha', 'github:user/repo#sha'],

0 commit comments

Comments
 (0)