Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 4f6b57e

Browse files
committed
Pass Git path to PullRequestTextBufferInfo
Consistently new up PullRequestTextBufferInfo with Git relative path.
1 parent 4bd5541 commit 4f6b57e

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

src/GitHub.App/Services/PullRequestEditorService.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,12 @@ public async Task<ITextView> OpenFile(
119119

120120
if (!workingDirectory)
121121
{
122-
AddBufferTag(wpfTextView.TextBuffer, session, fullPath, commitSha, null);
123-
EnableNavigateToEditor(textView, session);
122+
var gitPath = FindGitPath(session.LocalRepository, fullPath);
123+
if (gitPath != null)
124+
{
125+
AddBufferTag(wpfTextView.TextBuffer, session, gitPath, commitSha, null);
126+
EnableNavigateToEditor(textView, session);
127+
}
124128
}
125129
}
126130

@@ -485,6 +489,17 @@ static string GetAbsolutePath(LocalRepositoryModel localRepository, string relat
485489
return Path.Combine(localPath, relativePath);
486490
}
487491

492+
static string FindGitPath(LocalRepositoryModel localRepository, string path)
493+
{
494+
var basePath = localRepository.LocalPath + Path.DirectorySeparatorChar;
495+
if (path.StartsWith(basePath, StringComparison.OrdinalIgnoreCase))
496+
{
497+
return path.Substring(basePath.Length).Replace(Path.DirectorySeparatorChar, '/');
498+
}
499+
500+
return null;
501+
}
502+
488503
string GetText(IVsTextView textView)
489504
{
490505
IVsTextLines buffer;
@@ -561,21 +576,23 @@ void ShowErrorInStatusBar(string message, Exception e)
561576
void AddBufferTag(
562577
ITextBuffer buffer,
563578
IPullRequestSession session,
564-
string path,
579+
string gitPath,
565580
string commitSha,
566581
DiffSide? side)
567582
{
583+
Guard.ArgumentIsGitPath(gitPath, nameof(gitPath));
584+
568585
buffer.Properties.GetOrCreateSingletonProperty(
569586
typeof(PullRequestTextBufferInfo),
570-
() => new PullRequestTextBufferInfo(session, path, commitSha, side));
587+
() => new PullRequestTextBufferInfo(session, gitPath, commitSha, side));
571588

572589
var projection = buffer as IProjectionBuffer;
573590

574591
if (projection != null)
575592
{
576593
foreach (var source in projection.SourceBuffers)
577594
{
578-
AddBufferTag(source, session, path, commitSha, side);
595+
AddBufferTag(source, session, gitPath, commitSha, side);
579596
}
580597
}
581598
}

src/GitHub.InlineReviews/Services/PullRequestSession.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,6 @@ public async Task<string> GetMergeBase()
110110
return mergeBase;
111111
}
112112

113-
/// <inheritdoc/>
114-
public string GetRelativePath(string path)
115-
{
116-
if (Path.IsPathRooted(path))
117-
{
118-
var basePath = LocalRepository.LocalPath;
119-
120-
if (path.StartsWith(basePath, StringComparison.OrdinalIgnoreCase) && path.Length > basePath.Length + 1)
121-
{
122-
return path.Substring(basePath.Length + 1);
123-
}
124-
}
125-
126-
return null;
127-
}
128-
129113
/// <inheritdoc/>
130114
public async Task PostReviewComment(
131115
string body,

0 commit comments

Comments
 (0)