From d0354de8641ed1cc5c2844ba34eea8da51e10cf1 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 6 Feb 2018 16:56:05 -0500 Subject: [PATCH] Fixes issues opening the working file if renamed --- CHANGELOG.md | 1 + src/commands/openWorkingFile.ts | 7 +++++++ src/gitService.ts | 4 +++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7feb3cc..cbb80fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Fixed - Fixes [#35](https://github.com/eamodio/vscode-gitlens/issues/35) - Copy Commit Sha to Clipboard not working (linux) - Fixes issue where the last commit of a file history would be broken (failed to parse correctly) +- Fixes issue with *Open Working File* command (`gitlens.openWorkingFile`) failing when a file was renamed ## [8.0.0-beta3] - 2018-02-03 ### Added diff --git a/src/commands/openWorkingFile.ts b/src/commands/openWorkingFile.ts index 36ff4d8..46155c6 100644 --- a/src/commands/openWorkingFile.ts +++ b/src/commands/openWorkingFile.ts @@ -5,6 +5,7 @@ import { FileAnnotationType } from '../configuration'; import { Container } from '../container'; import { GitUri } from '../gitService'; import { Logger } from '../logger'; +import * as path from 'path'; export interface OpenWorkingFileCommandArgs { uri?: Uri; @@ -31,6 +32,12 @@ export class OpenWorkingFileCommand extends ActiveEditorCommand { if (uri === undefined) return undefined; args.uri = await GitUri.fromUri(uri); + if (args.uri instanceof GitUri && args.uri.sha) { + const [fileName, repoPath] = await Container.git.findWorkingFileName(args.uri.fsPath, args.uri.repoPath); + if (fileName !== undefined && repoPath !== undefined) { + args.uri = new GitUri(Uri.file(path.resolve(repoPath, fileName)), repoPath); + } + } } if (args.line !== undefined && args.line !== 0) { diff --git a/src/gitService.ts b/src/gitService.ts index a68ab03..603ee80 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -374,7 +374,9 @@ export class GitService extends Disposable { repoPath = await this.getRepoPath(fileName, { ref: ref }); [fileName, repoPath] = Git.splitPath(fileName, repoPath); } - + else { + fileName = Strings.normalizePath(path.relative(repoPath, fileName)); + } } else { const c = commitOrFileName;