Skip to content

Commit

Permalink
Added support for more git URL formats (#3445)
Browse files Browse the repository at this point in the history
  • Loading branch information
thedumbterminal authored and bestander committed May 19, 2017
1 parent dac451d commit 77ce1c9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions __tests__/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:\/\/((?:[^@:\/]+@)?([^@:\/]+):([^/]*).*)/);
Expand Down

0 comments on commit 77ce1c9

Please sign in to comment.