diff --git a/src/scm/localReplicaSCM.ts b/src/scm/localReplicaSCM.ts index 7b77293..52272ca 100644 --- a/src/scm/localReplicaSCM.ts +++ b/src/scm/localReplicaSCM.ts @@ -1,5 +1,6 @@ import * as vscode from 'vscode'; import * as DiffMatchPatch from 'diff-match-patch'; +import * as path from 'path'; import { minimatch } from 'minimatch'; import { BaseSCM, CommitItem, SettingItem } from "."; import { VirtualFileSystem, parseUri } from '../core/remoteFileSystemProvider'; @@ -346,9 +347,21 @@ export class LocalReplicaSCMProvider extends BaseSCM { */ private onDocumentSaved(doc: vscode.TextDocument) { const docUri = doc.uri; - // Only sync files within our baseUri (ensure path separator boundary) - const basePath = this.baseUri.path.endsWith('/') ? this.baseUri.path : this.baseUri.path + '/'; - if (!docUri.path.startsWith(basePath)) { return; } + + if (docUri.scheme!=='file' || this.baseUri.scheme!=='file') { return; } + + const basePath = path.resolve(this.baseUri.fsPath); + const docPath = path.resolve(docUri.fsPath); + const relativePath = path.relative(basePath, docPath); + if ( + relativePath==='' + || relativePath==='..' + || relativePath.startsWith(`..${path.sep}`) + || path.isAbsolute(relativePath) + ) { + return; + } + this.syncToVFS(docUri, 'update'); }