diff --git a/lib/util.js b/lib/util.js index 59110af0..2ac48c0c 100644 --- a/lib/util.js +++ b/lib/util.js @@ -48,7 +48,10 @@ const rejectAfter = (ms, error) => const parseGitUrl = remoteUrl => { if (!remoteUrl) return { host: null, owner: null, project: null, protocol: null, remote: null, repository: null }; - const normalizedUrl = (remoteUrl || '').replace(/^[A-Z]:/, '').replace(/\\/g, '/'); // Hacky workaround for file protocol in Windows + const normalizedUrl = (remoteUrl || '') + .replace(/^[A-Z]:\\\\/, 'file://') // Assume file protocol for Windows drive letters + .replace(/^\//, 'file://') // Assume file protocol if only /path is given + .replace(/\\+/g, '/'); // Replace forward with backslashes const parsedUrl = gitUrlParse(normalizedUrl); const { resource: host, name: project, protocol, href: remote } = parsedUrl; const owner = protocol === 'file' ? _.last(parsedUrl.owner.split('/')) : parsedUrl.owner; // Fix owner for file protocol diff --git a/test/git.js b/test/git.js index 1fbe8a1e..4b392243 100644 --- a/test/git.js +++ b/test/git.js @@ -274,7 +274,7 @@ test.serial('should reset files', async t => { test.serial('should roll back when cancelled', async t => { sh.exec('git init'); - sh.exec(`git remote add origin foo`); + sh.exec(`git remote add origin file://foo`); const version = '1.2.3'; gitAdd(`{"version":"${version}"}`, 'package.json', 'Add package.json'); const options = { git: { requireCleanWorkingDir: true, commit: true, tag: true, tagName: 'v${version}' } }; diff --git a/test/utils.js b/test/utils.js index 29d36bca..8fc34b1a 100644 --- a/test/utils.js +++ b/test/utils.js @@ -47,12 +47,39 @@ test('parseGitUrl', t => { repository: 'org/sub-group/repo-in-sub-group' }); + t.deepEqual(parseGitUrl('git@github.com:org/example.com.git'), { + host: 'github.com', + owner: 'org', + project: 'example.com', + protocol: 'ssh', + remote: 'git@github.com:org/example.com.git', + repository: 'org/example.com' + }); + + t.deepEqual(parseGitUrl('file://Users/john/doe/owner/project'), { + host: 'users', + owner: 'owner', + project: 'project', + protocol: 'file', + remote: 'file://users/john/doe/owner/project', + repository: 'owner/project' + }); + t.deepEqual(parseGitUrl('/Users/john/doe/owner/project'), { - host: '', + host: 'users', + owner: 'owner', + project: 'project', + protocol: 'file', + remote: 'file://users/john/doe/owner/project', + repository: 'owner/project' + }); + + t.deepEqual(parseGitUrl('C:\\\\Users\\john\\doe\\owner\\project'), { + host: 'users', owner: 'owner', project: 'project', protocol: 'file', - remote: '/Users/john/doe/owner/project', + remote: 'file://users/john/doe/owner/project', repository: 'owner/project' }); });