Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/GitHub.App/Services/PullRequestEditorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public async Task<ITextView> 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);
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -561,21 +573,23 @@ 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;

if (projection != null)
{
foreach (var source in projection.SourceBuffers)
{
AddBufferTag(source, session, path, commitSha, side);
AddBufferTag(source, session, gitPath, commitSha, side);
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions src/GitHub.InlineReviews/Services/PullRequestSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,6 @@ public async Task<string> GetMergeBase()
return mergeBase;
}

/// <inheritdoc/>
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;
}

/// <inheritdoc/>
public async Task PostReviewComment(
string body,
Expand Down