diff --git a/lib/package-managers/gitTags.js b/lib/package-managers/gitTags.js index 051d6ccd..bf487272 100644 --- a/lib/package-managers/gitTags.js +++ b/lib/package-managers/gitTags.js @@ -11,12 +11,22 @@ const getSortedVersions = async (name, declaration, options) => { // if present, github: is parsed as the protocol. This is not valid when passed into remote-git-tags. declaration = declaration.replace(/^github:/, '') const { auth, protocol, host, path } = parseGithubUrl(declaration) - const url = `${protocol ? protocol.replace('git+', '') : 'https:'}//${auth ? auth + '@' : ''}${host}/${path}` + let tagsPromise = Promise.resolve() + const protocolKnown = protocol != null + if (protocolKnown) { + tagsPromise = tagsPromise.then(() => remoteGitTags(`${protocol ? protocol.replace('git+', '') : 'https:'}//${auth ? auth + '@' : ''}${host}/${path}`)) + } + else { + // try ssh first, then https on failure + tagsPromise = tagsPromise.then(() => remoteGitTags(`ssh://git@${host}/${path}`)) + .catch(() => remoteGitTags(`https://${auth ? auth + '@' : ''}${host}/${path}`)) + } + let tagMap = new Map() // fetch remote tags try { - tagMap = await remoteGitTags(url) + tagMap = await tagsPromise } // catch a variety of errors that occur on invalid or private repos catch (e) {