diff --git a/src/GitHub.App/Services/PullRequestEditorService.cs b/src/GitHub.App/Services/PullRequestEditorService.cs index 597519f7ca..1ab40754ec 100644 --- a/src/GitHub.App/Services/PullRequestEditorService.cs +++ b/src/GitHub.App/Services/PullRequestEditorService.cs @@ -119,7 +119,8 @@ public async Task OpenFile( if (!workingDirectory) { - AddBufferTag(wpfTextView.TextBuffer, session, fullPath, commitSha, null); + var gitPath = ToGitPath(session.LocalRepository, fullPath); + AddBufferTag(wpfTextView.TextBuffer, session, gitPath, commitSha, null); EnableNavigateToEditor(textView, session); } } @@ -485,6 +486,17 @@ static string GetAbsolutePath(LocalRepositoryModel localRepository, string relat return Path.Combine(localPath, relativePath); } + static string ToGitPath(LocalRepositoryModel localRepository, string path) + { + var basePath = localRepository.LocalPath + Path.DirectorySeparatorChar; + if (path.StartsWith(basePath, StringComparison.OrdinalIgnoreCase)) + { + return path.Substring(basePath.Length).Replace(Path.DirectorySeparatorChar, '/'); + } + + throw new ArgumentException($"Path '{path}' is not in the working directory '{localRepository.LocalPath}'"); + } + string GetText(IVsTextView textView) { IVsTextLines buffer; @@ -561,13 +573,15 @@ void ShowErrorInStatusBar(string message, Exception e) void AddBufferTag( ITextBuffer buffer, IPullRequestSession session, - string path, + string gitPath, string commitSha, DiffSide? side) { + Guard.ArgumentIsGitPath(gitPath, nameof(gitPath)); + buffer.Properties.GetOrCreateSingletonProperty( typeof(PullRequestTextBufferInfo), - () => new PullRequestTextBufferInfo(session, path, commitSha, side)); + () => new PullRequestTextBufferInfo(session, gitPath, commitSha, side)); var projection = buffer as IProjectionBuffer; @@ -575,7 +589,7 @@ void AddBufferTag( { foreach (var source in projection.SourceBuffers) { - AddBufferTag(source, session, path, commitSha, side); + AddBufferTag(source, session, gitPath, commitSha, side); } } } diff --git a/src/GitHub.InlineReviews/Services/PullRequestSession.cs b/src/GitHub.InlineReviews/Services/PullRequestSession.cs index 783254237e..284f7cd37c 100644 --- a/src/GitHub.InlineReviews/Services/PullRequestSession.cs +++ b/src/GitHub.InlineReviews/Services/PullRequestSession.cs @@ -110,22 +110,6 @@ public async Task GetMergeBase() return mergeBase; } - /// - public string GetRelativePath(string path) - { - if (Path.IsPathRooted(path)) - { - var basePath = LocalRepository.LocalPath; - - if (path.StartsWith(basePath, StringComparison.OrdinalIgnoreCase) && path.Length > basePath.Length + 1) - { - return path.Substring(basePath.Length + 1); - } - } - - return null; - } - /// public async Task PostReviewComment( string body,