diff --git a/src/commands/diffWithRevisionFrom.ts b/src/commands/diffWithRevisionFrom.ts index da9d2f9..63026ef 100644 --- a/src/commands/diffWithRevisionFrom.ts +++ b/src/commands/diffWithRevisionFrom.ts @@ -86,7 +86,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand { const fileName = normalizePath(relative(gitUri.repoPath, gitUri.fsPath)); const rename = files.find(s => s.fileName === fileName); if (rename?.originalFileName != null) { - renamedUri = GitUri.resolveToUri(rename.originalFileName, gitUri.repoPath); + renamedUri = GitUri.resolve(rename.originalFileName, gitUri.repoPath); renamedTitle = `${basename(rename.originalFileName)} (${GitRevision.shorten(ref)})`; } } diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 43e0f80..dd43573 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -2624,7 +2624,7 @@ export class LocalGitProvider implements GitProvider, Disposable { else { ref = blameLine.commit.sha; fileName = blameLine.commit.fileName || (blameLine.commit.originalFileName ?? fileName); - uri = GitUri.resolveToUri(fileName, repoPath); + uri = GitUri.resolve(fileName, repoPath); editorLine = blameLine.line.originalLine - 1; if (skip === 0 && blameLine.commit.previousSha) { @@ -2653,7 +2653,7 @@ export class LocalGitProvider implements GitProvider, Disposable { // Diff with line ref with previous ref = blameLine.commit.sha; fileName = blameLine.commit.fileName || (blameLine.commit.originalFileName ?? fileName); - uri = GitUri.resolveToUri(fileName, repoPath); + uri = GitUri.resolve(fileName, repoPath); editorLine = blameLine.line.originalLine - 1; if (skip === 0 && blameLine.commit.previousSha) { @@ -3367,7 +3367,7 @@ export class LocalGitProvider implements GitProvider, Disposable { fileName = foundFile; } while (true); - uri = GitUri.resolveToUri(fileName, repoPath); + uri = GitUri.resolve(fileName, repoPath); return (await fsExists(uri.fsPath)) ? uri : undefined; } diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index 5461f7d..a2c0f8a 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -99,10 +99,20 @@ export class GitUri extends (Uri as any as UriEx) { return; } - const [authority, fsPath] = GitUri.ensureValidUNCPath( - uri.authority, - GitUri.resolve(commitOrRepoPath.fileName ?? uri.fsPath, commitOrRepoPath.repoPath), - ); + let authority = uri.authority; + let fsPath = GitUri.resolvePath(commitOrRepoPath.fileName ?? uri.fsPath, commitOrRepoPath.repoPath); + + // Check for authority as used in UNC shares or use the path as given + if (fsPath.charCodeAt(0) === CharCode.Slash && fsPath.charCodeAt(1) === CharCode.Slash) { + const index = fsPath.indexOf('/', 2); + if (index === -1) { + authority = fsPath.substring(2); + fsPath = '/'; + } else { + authority = fsPath.substring(2, index); + fsPath = fsPath.substring(index) || '/'; + } + } let path; switch (uri.scheme) { @@ -198,22 +208,6 @@ export class GitUri extends (Uri as any as UriEx) { return GitUri.file(this.fsPath); } - private static ensureValidUNCPath(authority: string, fsPath: string): [string, string] { - // Check for authority as used in UNC shares or use the path as given - if (fsPath.charCodeAt(0) === CharCode.Slash && fsPath.charCodeAt(1) === CharCode.Slash) { - const index = fsPath.indexOf('/', 2); - if (index === -1) { - authority = fsPath.substring(2); - fsPath = '/'; - } else { - authority = fsPath.substring(2, index); - fsPath = fsPath.substring(index) || '/'; - } - } - - return [authority, fsPath]; - } - static file(path: string, useVslsScheme?: boolean) { const uri = Uri.file(path); if (Container.instance.vsls.isMaybeGuest && useVslsScheme !== false) { @@ -233,7 +227,7 @@ export class GitUri extends (Uri as any as UriEx) { } static fromFile(file: string | GitFile, repoPath: string, ref?: string, original: boolean = false): GitUri { - const uri = GitUri.resolveToUri( + const uri = GitUri.resolve( typeof file === 'string' ? file : (original && file.originalFileName) || file.fileName, repoPath, ); @@ -413,7 +407,7 @@ export class GitUri extends (Uri as any as UriEx) { } static git(fileName: string, repoPath?: string) { - const path = GitUri.resolve(fileName, repoPath); + const path = GitUri.resolvePath(fileName, repoPath); return Uri.parse( // Change encoded / back to / otherwise uri parsing won't work properly `${DocumentSchemes.Git}:/${encodeURIComponent(path).replace(/%2F/g, '/')}?${encodeURIComponent( @@ -426,7 +420,7 @@ export class GitUri extends (Uri as any as UriEx) { ); } - static resolve(fileName: string, repoPath?: string) { + static resolvePath(fileName: string, repoPath?: string) { const normalizedFileName = normalizePath(fileName); if (repoPath === undefined) return normalizedFileName; @@ -438,8 +432,8 @@ export class GitUri extends (Uri as any as UriEx) { return normalizePath(joinPaths(normalizedRepoPath, normalizedFileName)); } - static resolveToUri(fileName: string, repoPath?: string) { - return GitUri.file(this.resolve(fileName, repoPath)); + static resolve(fileName: string, repoPath?: string) { + return GitUri.file(this.resolvePath(fileName, repoPath)); } static toKey(fileName: string): string; @@ -466,7 +460,7 @@ export class GitUri extends (Uri as any as UriEx) { fileName = fileNameOrFile; } else { //if (fileNameOrFile!.status === 'D') { - fileName = GitUri.resolve(fileNameOrFile!.originalFileName ?? fileNameOrFile!.fileName, repoPath); + fileName = GitUri.resolvePath(fileNameOrFile!.originalFileName ?? fileNameOrFile!.fileName, repoPath); // } else { // fileName = GitUri.resolve(fileNameOrFile!.fileName, repoPath); } diff --git a/src/git/models/commit.ts b/src/git/models/commit.ts index f16b131..a937928 100644 --- a/src/git/models/commit.ts +++ b/src/git/models/commit.ts @@ -126,7 +126,7 @@ export abstract class GitCommit implements GitRevisionReference { @memoize() get originalUri(): Uri { - return this.originalFileName ? GitUri.resolveToUri(this.originalFileName, this.repoPath) : this.uri; + return this.originalFileName ? GitUri.resolve(this.originalFileName, this.repoPath) : this.uri; } get previousFileSha(): string { @@ -138,12 +138,12 @@ export abstract class GitCommit implements GitRevisionReference { } get previousUri(): Uri { - return this.previousFileName ? GitUri.resolveToUri(this.previousFileName, this.repoPath) : this.uri; + return this.previousFileName ? GitUri.resolve(this.previousFileName, this.repoPath) : this.uri; } @memoize() get uri(): Uri { - return GitUri.resolveToUri(this.fileName, this.repoPath); + return GitUri.resolve(this.fileName, this.repoPath); } @memoize() diff --git a/src/git/models/logCommit.ts b/src/git/models/logCommit.ts index edf3864..47c3061 100644 --- a/src/git/models/logCommit.ts +++ b/src/git/models/logCommit.ts @@ -90,7 +90,7 @@ export class GitLogCommit extends GitCommit { } get nextUri(): Uri { - return this.nextFileName ? GitUri.resolveToUri(this.nextFileName, this.repoPath) : this.uri; + return this.nextFileName ? GitUri.resolve(this.nextFileName, this.repoPath) : this.uri; } override get previousFileSha(): string { diff --git a/src/git/models/status.ts b/src/git/models/status.ts index e1d41d7..81581dc 100644 --- a/src/git/models/status.ts +++ b/src/git/models/status.ts @@ -403,7 +403,7 @@ export class GitStatusFile implements GitFile { @memoize() get uri(): Uri { - return GitUri.resolveToUri(this.fileName, this.repoPath); + return GitUri.resolve(this.fileName, this.repoPath); } getFormattedDirectory(includeOriginal: boolean = false): string { diff --git a/src/views/nodes/mergeConflictFileNode.ts b/src/views/nodes/mergeConflictFileNode.ts index 3274902..5c874df 100644 --- a/src/views/nodes/mergeConflictFileNode.ts +++ b/src/views/nodes/mergeConflictFileNode.ts @@ -53,7 +53,7 @@ export class MergeConflictFileNode extends ViewNode implements this.file, ); // Use the file icon and decorations - item.resourceUri = GitUri.resolveToUri(this.file.fileName, this.repoPath); + item.resourceUri = GitUri.resolve(this.file.fileName, this.repoPath); item.iconPath = ThemeIcon.File; item.command = this.getCommand(); @@ -115,7 +115,7 @@ export class MergeConflictFileNode extends ViewNode implements title: 'Open File', command: BuiltInCommands.Open, arguments: [ - GitUri.resolveToUri(this.file.fileName, this.repoPath), + GitUri.resolve(this.file.fileName, this.repoPath), { preserveFocus: true, preview: true, diff --git a/src/views/nodes/statusFileNode.ts b/src/views/nodes/statusFileNode.ts index 3addda8..564945a 100644 --- a/src/views/nodes/statusFileNode.ts +++ b/src/views/nodes/statusFileNode.ts @@ -87,7 +87,7 @@ export class StatusFileNode extends ViewNode implements FileNo } // Use the file icon and decorations - item.resourceUri = GitUri.resolveToUri(this.file.fileName, this.repoPath); + item.resourceUri = GitUri.resolve(this.file.fileName, this.repoPath); item.iconPath = ThemeIcon.File; item.command = this.getCommand(); @@ -104,7 +104,7 @@ export class StatusFileNode extends ViewNode implements FileNo } // Use the file icon and decorations - item.resourceUri = GitUri.resolveToUri(this.file.fileName, this.repoPath); + item.resourceUri = GitUri.resolve(this.file.fileName, this.repoPath); item.iconPath = ThemeIcon.File; } else { item.contextValue = ContextValues.StatusFileCommits; diff --git a/src/vsls/host.ts b/src/vsls/host.ts index e2a89e2..228fe1a 100644 --- a/src/vsls/host.ts +++ b/src/vsls/host.ts @@ -155,7 +155,7 @@ export class VslsHostService implements Disposable { const localCwd = this._sharedToLocalPaths.get('/~0'); if (localCwd !== undefined) { isRootWorkspace = true; - options.cwd = GitUri.resolve(options.cwd, localCwd); + options.cwd = GitUri.resolvePath(options.cwd, localCwd); } } }