8000 Be consistent about how we use relative paths and Git paths by jcansdale · Pull Request #2386 · github/VisualStudio · GitHub
[go: up one dir, main page]

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

Be consistent about how we use relative paths and Git paths #2386

Merged
merged 11 commits into from
Aug 9, 2019
Merged
Next Next commit
Pass Git path to PullRequestTextBufferInfo
Consistently new up PullRequestTextBufferInfo with Git relative path.
  • Loading branch information
jcansdale committed Jun 10, 2019
commit 4f6b57efb03ca76db498539380b75a8d548c748f
27 changes: 22 additions & 5 deletions src/GitHub.App/Services/PullRequestEditorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ public async Task<ITextView> OpenFile(

if (!workingDirectory)
{
AddBufferTag(wpfTextView.TextBuffer, session, fullPath, commitSha, null);
EnableNavigateToEditor(textView, session);
var gitPath = FindGitPath(session.LocalRepository, fullPath);
if (gitPath != null)
{
AddBufferTag(wpfTextView.TextBuffer, session, gitPath, commitSha, null);
EnableNavigateToEditor(textView, session);
}
}
}

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

static string FindGitPath(LocalRepositoryModel localRepository, string path)
{
var basePath = localRepository.LocalPath + Path.DirectorySeparatorChar;
if (path.StartsWith(basePath, StringComparison.OrdinalIgnoreCase))
{
return path.Substring(basePath.Length).Replace(Path.DirectorySeparatorChar, '/');
}

return null;
}

string GetText(IVsTextView textView)
{
IVsTextLines buffer;
Expand Down Expand Up @@ -561,21 +576,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
0