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

Commit 8ae29c8

Browse files
StanleyGoldmanjcansdale
authored andcommitted
FindGitRelativePath should always return a path or error
co-authoried-by: Jamie Cansdale <[email protected]>
1 parent 4f6b57e commit 8ae29c8

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/GitHub.App/Services/PullRequestEditorService.cs

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

120120
if (!workingDirectory)
121121
{
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-
}
122+
var gitPath = ToGitPath(session.LocalRepository, fullPath);
123+
AddBufferTag(wpfTextView.TextBuffer, session, gitPath, commitSha, null);
124+
EnableNavigateToEditor(textView, session);
128125
}
129126
}
130127

@@ -489,15 +486,15 @@ static string GetAbsolutePath(LocalRepositoryModel localRepository, string relat
489486
return Path.Combine(localPath, relativePath);
490487
}
491488

492-
static string FindGitPath(LocalRepositoryModel localRepository, string path)
489+
static string ToGitPath(LocalRepositoryModel localRepository, string path)
493490
{
494491
var basePath = localRepository.LocalPath + Path.DirectorySeparatorChar;
495492
if (path.StartsWith(basePath, StringComparison.OrdinalIgnoreCase))
496493
{
497494
return path.Substring(basePath.Length).Replace(Path.DirectorySeparatorChar, '/');
498495
}
499496

500-
return null;
497+
throw new ArgumentException($"Path '{path}' is not in the working directory '{localRepository.LocalPath}'");
501498
}
502499

503500
string GetText(IVsTextView textView)

0 commit comments

Comments
 (0)