diff --git a/package.json b/package.json index e7487649f..7df2ba07c 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "listr": "^0.14.3", "log-symbols": "^3.0.0", "micromatch": "^4.0.2", + "normalize-path": "^3.0.0", "please-upgrade-node": "^3.1.1", "string-argv": "^0.3.0", "stringify-object": "^3.3.0" diff --git a/src/resolveGitDir.js b/src/resolveGitDir.js index 28d585676..cf04c4ca5 100644 --- a/src/resolveGitDir.js +++ b/src/resolveGitDir.js @@ -1,7 +1,7 @@ 'use strict' const execGit = require('./execGit') -const path = require('path') +const normalize = require('normalize-path') module.exports = async function resolveGitDir(options = {}) { try { @@ -9,7 +9,7 @@ module.exports = async function resolveGitDir(options = {}) { // depending on where the caller initiated this from, hence clear GIT_DIR delete process.env.GIT_DIR const gitDir = await execGit(['rev-parse', '--show-toplevel'], options) - return path.resolve(gitDir) + return normalize(gitDir) } catch (error) { return null } diff --git a/test/resolveGitDir.spec.js b/test/resolveGitDir.spec.js index 53e4e8d7d..0c4ed6424 100644 --- a/test/resolveGitDir.spec.js +++ b/test/resolveGitDir.spec.js @@ -1,4 +1,6 @@ +import normalize from 'normalize-path' import path from 'path' + import resolveGitDir from '../src/resolveGitDir' /** @@ -8,12 +10,12 @@ jest.unmock('execa') describe('resolveGitDir', () => { it('should resolve to current working dir when .git is in the same dir', async () => { - const expected = process.cwd() + const expected = normalize(process.cwd()) expect(await resolveGitDir()).toEqual(expected) }) it('should resolve to the parent dir when .git is in the parent dir', async () => { - const expected = path.dirname(__dirname) + const expected = normalize(path.dirname(__dirname)) const processCwdBkp = process.cwd process.cwd = () => __dirname // path.resolve to strip trailing slash @@ -22,7 +24,7 @@ describe('resolveGitDir', () => { }) it('should resolve to the parent dir when .git is in the parent dir even when the GIT_DIR environment variable is set', async () => { - const expected = path.dirname(__dirname) + const expected = normalize(path.dirname(__dirname)) const processCwdBkp = process.cwd process.cwd = () => __dirname process.env.GIT_DIR = 'wrong/path/.git' // refer to https://github.com/DonJayamanne/gitHistoryVSCode/issues/233#issuecomment-375769718 diff --git a/yarn.lock b/yarn.lock index ea5f3247c..c7b9b825b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4296,6 +4296,11 @@ normalize-path@^2.1.1: dependencies: remove-trailing-separator "^1.0.1" +normalize-path@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65" + integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== + npm-bundled@^1.0.1: version "1.0.6" resolved "https://registry.yarnpkg.com/npm-bundled/-/npm-bundled-1.0.6.tgz#e7ba9aadcef962bb61248f91721cd932b3fe6bdd"