Skip to content

Commit d50f2cb

Browse files
mattseddonsroy3
andauthored
Fix DVC cwd for Windows (#1921)
* fix DVC cwd on Windows * add integration test in environment where fs is available * add system specific test Co-authored-by: Stephanie Roy <[email protected]>
1 parent c5ee920 commit d50f2cb

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

extension/src/cli/cwd.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { realpathSync } from 'fs'
2+
3+
export const getCaseSensitiveCwd = (path: string): string => {
4+
try {
5+
const cwd = realpathSync.native(path)
6+
if (cwd) {
7+
return cwd
8+
}
9+
} catch {}
10+
return path
11+
}

extension/src/cli/options.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { dirname } from 'path'
22
import { Args } from './constants'
3+
import { getCaseSensitiveCwd } from './cwd'
34
import { getProcessEnv } from '../env'
45
import { joinEnvPath } from '../util/env'
56

@@ -45,13 +46,11 @@ export const getOptions = (
4546
): ExecutionDetails => {
4647
const executable = getExecutable(pythonBinPath, cliPath)
4748
const args = getArgs(pythonBinPath, cliPath, ...originalArgs)
48-
const command = [executable, ...args].join(' ')
49-
const env = getEnv(pythonBinPath)
5049
return {
5150
args,
52-
command,
53-
cwd,
54-
env,
51+
command: [executable, ...args].join(' '),
52+
cwd: getCaseSensitiveCwd(cwd),
53+
env: getEnv(pythonBinPath),
5554
executable
5655
}
5756
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { sep } from 'path'
2+
import { describe, it, suite } from 'mocha'
3+
import { expect } from 'chai'
4+
import { dvcDemoPath } from '../../util'
5+
import { getCaseSensitiveCwd } from '../../../cli/cwd'
6+
7+
suite('Cwd Test Suite', () => {
8+
describe('getCaseSensitiveCwd', () => {
9+
it('should return a case sensitive path for case sensitive systems which matches os.getcwd() in the CLI', () => {
10+
const caseInsensitiveCwd = dvcDemoPath.toUpperCase()
11+
const realpathCwd = getCaseSensitiveCwd(caseInsensitiveCwd)
12+
13+
expect(realpathCwd).to.have.length(dvcDemoPath.length)
14+
expect(realpathCwd).not.to.equal(
15+
['win32', 'darwin'].includes(process.platform)
16+
? caseInsensitiveCwd
17+
: caseInsensitiveCwd.toLowerCase(),
18+
'should behave differently on different systems'
19+
)
20+
21+
const caseInsensitiveArray = caseInsensitiveCwd.split(sep)
22+
const realPathArray = realpathCwd.split(sep)
23+
24+
expect(caseInsensitiveArray).to.have.length(realPathArray.length)
25+
for (let i = 0; i <= caseInsensitiveArray.length; i++) {
26+
expect(caseInsensitiveArray[i]).to.match(
27+
new RegExp(realPathArray[i], 'i')
28+
)
29+
}
30+
})
31+
})
32+
})

0 commit comments

Comments
 (0)