mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-26 12:44:05 +00:00
Git - fix repository detection when rev-parse returns a UNC path on Windows (#230207)
This commit is contained in:
@@ -484,6 +484,17 @@ export class Git {
|
||||
// Keep trailing spaces which are part of the directory name
|
||||
const repositoryRootPath = path.normalize(result.stdout.trimStart().replace(/[\r\n]+$/, ''));
|
||||
|
||||
// Handle symbolic links and UNC paths
|
||||
// Git 2.31 added the `--path-format` flag to rev-parse which
|
||||
// allows us to get the relative path of the repository root
|
||||
if (!pathEquals(pathInsidePossibleRepository, repositoryRootPath) &&
|
||||
!isDescendant(repositoryRootPath, pathInsidePossibleRepository) &&
|
||||
!isDescendant(pathInsidePossibleRepository, repositoryRootPath) &&
|
||||
this.compareGitVersionTo('2.31.0') !== -1) {
|
||||
const relativePathResult = await this.exec(pathInsidePossibleRepository, ['rev-parse', '--path-format=relative', '--show-toplevel',]);
|
||||
return path.resolve(pathInsidePossibleRepository, relativePathResult.stdout.trimStart().replace(/[\r\n]+$/, ''));
|
||||
}
|
||||
|
||||
if (isWindows) {
|
||||
// On Git 2.25+ if you call `rev-parse --show-toplevel` on a mapped drive, instead of getting the mapped
|
||||
// drive path back, you get the UNC path for the mapped drive. So we will try to normalize it back to the
|
||||
@@ -520,17 +531,6 @@ export class Git {
|
||||
}
|
||||
}
|
||||
|
||||
// Handle symbolic links
|
||||
// Git 2.31 added the `--path-format` flag to rev-parse which
|
||||
// allows us to get the relative path of the repository root
|
||||
if (!pathEquals(pathInsidePossibleRepository, repositoryRootPath) &&
|
||||
!isDescendant(repositoryRootPath, pathInsidePossibleRepository) &&
|
||||
!isDescendant(pathInsidePossibleRepository, repositoryRootPath) &&
|
||||
this.compareGitVersionTo('2.31.0') !== -1) {
|
||||
const relativePathResult = await this.exec(pathInsidePossibleRepository, ['rev-parse', '--path-format=relative', '--show-toplevel',]);
|
||||
return path.resolve(pathInsidePossibleRepository, relativePathResult.stdout.trimStart().replace(/[\r\n]+$/, ''));
|
||||
}
|
||||
|
||||
return repositoryRootPath;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user