diff --git a/src/commands/closeUnchangedFiles.ts b/src/commands/closeUnchangedFiles.ts index 57f71f6..5c755f2 100644 --- a/src/commands/closeUnchangedFiles.ts +++ b/src/commands/closeUnchangedFiles.ts @@ -5,7 +5,6 @@ import { ActiveEditorCommand, Commands } from './common'; import { TextEditorComparer, UriComparer } from '../comparers'; import { GitService } from '../gitService'; import { Logger } from '../logger'; -import * as path from 'path'; export class CloseUnchangedFilesCommand extends ActiveEditorCommand { @@ -26,7 +25,7 @@ export class CloseUnchangedFilesCommand extends ActiveEditorCommand { const status = await this.git.getStatusForRepo(repoPath); if (!status) return window.showWarningMessage(`Unable to close unchanged files`); - uris = status.files.map(_ => Uri.file(path.resolve(repoPath, _.fileName))); + uris = status.files.map(_ => _.Uri); } const editorTracker = new ActiveEditorTracker(); diff --git a/src/commands/openChangedFiles.ts b/src/commands/openChangedFiles.ts index 08d2837..324319d 100644 --- a/src/commands/openChangedFiles.ts +++ b/src/commands/openChangedFiles.ts @@ -3,7 +3,6 @@ import { TextEditor, Uri, window } from 'vscode'; import { ActiveEditorCommand, Commands, openEditor } from './common'; import { GitService } from '../gitService'; import { Logger } from '../logger'; -import * as path from 'path'; export class OpenChangedFilesCommand extends ActiveEditorCommand { @@ -24,7 +23,7 @@ export class OpenChangedFilesCommand extends ActiveEditorCommand { const status = await this.git.getStatusForRepo(repoPath); if (!status) return window.showWarningMessage(`Unable to open changed files`); - uris = status.files.filter(_ => _.status !== 'D').map(_ => Uri.file(path.resolve(repoPath, _.fileName))); + uris = status.files.filter(_ => _.status !== 'D').map(_ => _.Uri); } for (const uri of uris) { diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index 903c245..b97458b 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -1,7 +1,7 @@ 'use strict'; import { Uri } from 'vscode'; import { DocumentSchemes } from '../constants'; -import { Git, GitService } from '../gitService'; +import { Git, GitCommit, GitService, IGitStatusFile } from '../gitService'; import * as path from 'path'; export class GitUri extends Uri { @@ -12,6 +12,7 @@ export class GitUri extends Uri { constructor(uri?: Uri, commit?: IGitCommitInfo); constructor(uri?: Uri, repoPath?: string); + constructor(uri?: Uri, commitOrRepoPath?: IGitCommitInfo | string); constructor(uri?: Uri, commitOrRepoPath?: IGitCommitInfo | string) { super(); if (!uri) return; @@ -88,6 +89,14 @@ export class GitUri extends Uri { return new GitUri(uri, git && git.repoPath); } + + static fromFileStatus(status: IGitStatusFile, repoPath: string, original?: boolean): GitUri; + static fromFileStatus(status: IGitStatusFile, commit: GitCommit, original?: boolean): GitUri; + static fromFileStatus(status: IGitStatusFile, repoPathOrCommit: string | GitCommit, original: boolean = false): GitUri { + const repoPath = repoPathOrCommit instanceof GitCommit ? repoPathOrCommit.repoPath : repoPathOrCommit; + const uri = Uri.file(path.resolve(repoPath, original ? status.originalFileName || status.fileName : status.fileName)); + return new GitUri(uri, repoPathOrCommit); + } } export interface IGitCommitInfo { diff --git a/src/quickPicks/commitDetails.ts b/src/quickPicks/commitDetails.ts index cd622d7..e6e3f2a 100644 --- a/src/quickPicks/commitDetails.ts +++ b/src/quickPicks/commitDetails.ts @@ -34,7 +34,7 @@ export class CommitWithFileStatusQuickPickItem extends OpenFileCommandQuickPickI }); this.fileName = status.fileName; - this.gitUri = new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName))); + this.gitUri = GitUri.fromFileStatus(status, commit.repoPath); this.sha = commit.sha; this.shortSha = commit.shortSha; this.status = status.status; @@ -58,7 +58,7 @@ export class OpenCommitWorkingTreeFilesCommandQuickPickItem extends OpenFilesCom constructor(commit: GitLogCommit, versioned: boolean = false, item?: QuickPickItem) { const repoPath = commit.repoPath; - const uris = commit.fileStatuses.map(_ => Uri.file(path.resolve(repoPath, _.fileName))); + const uris = commit.fileStatuses.map(_ => GitUri.fromFileStatus(_, repoPath)); super(uris, item || { label: `$(file-symlink-file) Open Changed Working Files`, description: undefined