From 77ce1c9f943865ebb83fb637362696990360cdab Mon Sep 17 00:00:00 2001 From: The Dumb Terminal Date: Fri, 19 May 2017 12:56:38 +0100 Subject: [PATCH] Added support for more git URL formats (#3445) --- __tests__/util/git.js | 20 ++++++++++++++++++++ src/util/git.js | 3 +++ 2 files changed, 23 insertions(+) diff --git a/__tests__/util/git.js b/__tests__/util/git.js index 7a02b7cdc9..3314ee64ca 100644 --- a/__tests__/util/git.js +++ b/__tests__/util/git.js @@ -41,6 +41,26 @@ test('npmUrlToGitUrl', () => { hostname: 'scp-host-nickname', repository: 'user@scp-host-nickname:npm-opam/ocamlfind.git', }); + expect(Git.npmUrlToGitUrl('github:npm-opam/ocamlfind.git#v1.2.3')).toEqual({ + protocol: 'ssh:', + hostname: 'github.com', + repository: 'ssh://git@github.com/npm-opam/ocamlfind.git#v1.2.3', + }); + expect(Git.npmUrlToGitUrl('github:npm-opam/ocamlfind#v1.2.3')).toEqual({ + protocol: 'ssh:', + hostname: 'github.com', + repository: 'ssh://git@github.com/npm-opam/ocamlfind#v1.2.3', + }); + expect(Git.npmUrlToGitUrl('github:npm-opam/ocamlfind.git')).toEqual({ + protocol: 'ssh:', + hostname: 'github.com', + repository: 'ssh://git@github.com/npm-opam/ocamlfind.git', + }); + expect(Git.npmUrlToGitUrl('github:npm-opam/ocamlfind')).toEqual({ + protocol: 'ssh:', + hostname: 'github.com', + repository: 'ssh://git@github.com/npm-opam/ocamlfind', + }); }); test('isCommitHash', () => { diff --git a/src/util/git.js b/src/util/git.js index c2e6f58ae0..2814732b34 100644 --- a/src/util/git.js +++ b/src/util/git.js @@ -62,6 +62,9 @@ export default class Git { * git "URLs" also allow an alternative scp-like syntax, so they're not standard URLs. */ static npmUrlToGitUrl(npmUrl: string): GitUrl { + // Expand shortened format first if needed + npmUrl = npmUrl.replace(/^github:/, 'git+ssh://git@github.com/'); + // Special case in npm, where ssh:// prefix is stripped to pass scp-like syntax // which in git works as remote path only if there are no slashes before ':'. const match = npmUrl.match(/^git\+ssh:\/\/((?:[^@:\/]+@)?([^@:\/]+):([^/]*).*)/);