Skip to content

Commit

Permalink
fix: preserve drive letter on windows git file:// urls
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Aug 21, 2019
1 parent a5a18b3 commit 3909203
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions npa.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ function fromURL (res) {
} else {
setGitCommittish(res, urlparse.hash != null ? urlparse.hash.slice(1) : '')
urlparse.protocol = urlparse.protocol.replace(/^git[+]/, '')
if (urlparse.protocol === 'file:' && /^git\+file:\/\/[a-z]:/i.test(res.rawSpec)) {
// keep the drive letter : on windows file paths
urlparse.host += ':'
urlparse.hostname += ':'
}
delete urlparse.hash
res.fetchSpec = url.format(urlparse)
}
Expand Down
15 changes: 15 additions & 0 deletions test/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ var cases = {
rawSpec: '/foo/bar/baz',
fetchSpec: '/foo/bar/baz',
type: 'directory'
},
'foo@git+file://C:\\x\\y\\z': {
type: 'git',
registry: null,
where: null,
raw: 'foo@git+file://C:\\x\\y\\z',
name: 'foo',
escapedName: 'foo',
scope: null,
rawSpec: 'git+file://C:\\x\\y\\z',
saveSpec: 'git+file://C:\\x\\y\\z',
fetchSpec: 'file://c:/x/y/z',
gitRange: null,
gitCommittish: null,
hosted: null
}
}

Expand Down

0 comments on commit 3909203

Please sign in to comment.