Merge pull request #10926 from atom/fix-case-sensitive-path-relativization

Fix case-preserving path relativization
This commit is contained in:
Josh Abernathy
2016-02-22 12:49:03 -05:00
committed by joshaber
parent 6d0d388e04
commit 2a9701ac7c
2 changed files with 21 additions and 10 deletions

View File

@@ -590,6 +590,14 @@ describe('GitRepositoryAsync', () => {
const relativizedPath = repo.relativize(`${workdir}/a/b.txt`, workdir)
expect(relativizedPath).toBe('a/b.txt')
})
it('preserves file case', () => {
repo.isCaseInsensitive = true
const workdir = '/tmp/foo/bar/baz/'
const relativizedPath = repo.relativize(`${workdir}a/README.txt`, workdir)
expect(relativizedPath).toBe('a/README.txt')
})
})
describe('.getShortHead(path)', () => {

View File

@@ -202,32 +202,35 @@ export default class GitRepositoryAsync {
workingDirectory = workingDirectory.replace(/\/$/, '')
// Depending on where the paths come from, they may have a '/private/'
// prefix. Standardize by stripping that out.
_path = _path.replace(/^\/private\//i, '/')
workingDirectory = workingDirectory.replace(/^\/private\//i, '/')
const originalPath = _path
const originalWorkingDirectory = workingDirectory
if (this.isCaseInsensitive) {
_path = _path.toLowerCase()
workingDirectory = workingDirectory.toLowerCase()
}
// Depending on where the paths come from, they may have a '/private/'
// prefix. Standardize by stripping that out.
_path = _path.replace(/^\/private\//, '/')
workingDirectory = workingDirectory.replace(/^\/private\//, '/')
const originalPath = _path
if (_path.indexOf(workingDirectory) === 0) {
return originalPath.substring(workingDirectory.length + 1)
return originalPath.substring(originalWorkingDirectory.length + 1)
} else if (_path === workingDirectory) {
return ''
}
if (openedWorkingDirectory) {
openedWorkingDirectory = openedWorkingDirectory.replace(/\/$/, '')
openedWorkingDirectory = openedWorkingDirectory.replace(/^\/private\//i, '/')
const originalOpenedWorkingDirectory = openedWorkingDirectory
if (this.isCaseInsensitive) {
openedWorkingDirectory = openedWorkingDirectory.toLowerCase()
}
openedWorkingDirectory = openedWorkingDirectory.replace(/\/$/, '')
openedWorkingDirectory = openedWorkingDirectory.replace(/^\/private\//, '/')
if (_path.indexOf(openedWorkingDirectory) === 0) {
return originalPath.substring(openedWorkingDirectory.length + 1)
return originalPath.substring(originalOpenedWorkingDirectory.length + 1)
} else if (_path === openedWorkingDirectory) {
return ''
}