diff options
Diffstat (limited to 'extensions/git/src/model.ts')
-rw-r--r-- | extensions/git/src/model.ts | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/extensions/git/src/model.ts b/extensions/git/src/model.ts index a6e835043a8..71ac937c6f8 100644 --- a/extensions/git/src/model.ts +++ b/extensions/git/src/model.ts @@ -105,6 +105,7 @@ export class Model implements IRemoteSourcePublisherRegistry, IPushErrorHandlerR private _onDidRemoveRemoteSourcePublisher = new EventEmitter<RemoteSourcePublisher>(); readonly onDidRemoveRemoteSourcePublisher = this._onDidRemoveRemoteSourcePublisher.event; + private showRepoOnHomeDriveRootWarning = true; private pushErrorHandlers = new Set<PushErrorHandler>(); private disposables: Disposable[] = []; @@ -309,7 +310,7 @@ export class Model implements IRemoteSourcePublisherRegistry, IPushErrorHandlerR // Check if the folder is a bare repo: if it has a file named HEAD && `rev-parse --show -cdup` is empty try { fs.accessSync(path.join(repoPath, 'HEAD'), fs.constants.F_OK); - const result = await this.git.exec(repoPath, ['-C', repoPath, 'rev-parse', '--show-cdup'], { log: false }); + const result = await this.git.exec(repoPath, ['-C', repoPath, 'rev-parse', '--show-cdup']); if (result.stderr.trim() === '' && result.stdout.trim() === '') { return; } @@ -334,6 +335,22 @@ export class Model implements IRemoteSourcePublisherRegistry, IPushErrorHandlerR return; } + // On Window, opening a git repository from the root of the HOMEDRIVE poses a security risk. + // We will only a open git repository from the root of the HOMEDRIVE if the user explicitly + // opens the HOMEDRIVE as a folder. Only show the warning once during repository discovery. + if (process.platform === 'win32' && process.env.HOMEDRIVE && pathEquals(`${process.env.HOMEDRIVE}\\`, repositoryRoot)) { + const isRepoInWorkspaceFolders = (workspace.workspaceFolders ?? []).find(f => pathEquals(f.uri.fsPath, repositoryRoot))!!; + + if (!isRepoInWorkspaceFolders) { + if (this.showRepoOnHomeDriveRootWarning) { + window.showWarningMessage(localize('repoOnHomeDriveRootWarning', "Unable to automatically open the git repository at '{0}'. To open that git repository, open it directly as a folder in VS Code.", repositoryRoot)); + this.showRepoOnHomeDriveRootWarning = false; + } + + return; + } + } + const dotGit = await this.git.getRepositoryDotGit(repositoryRoot); const repository = new Repository(this.git.open(repositoryRoot, dotGit), this, this, this.globalState, this.outputChannel, this.telemetryReporter); |