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

Commit 0d0ad94

Browse files
committed
Make compare view editable.
Make PR file compare view editable if PR branch is checked out.
1 parent 437ae09 commit 0d0ad94

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public PullRequestDetailViewModelDesigner()
7070
public IPullRequestModel Model { get; }
7171
public string SourceBranchDisplayName { get; set; }
7272
public string TargetBranchDisplayName { get; set; }
73+
public bool IsCheckedOut { get; }
7374
public bool IsFromFork { get; }
7475
public string Body { get; }
7576
public IReactiveList<IPullRequestChangeNode> ChangedFilesTree { get; }

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ public IObservable<Tuple<string, string>> ExtractDiffFiles(
287287
IModelService modelService,
288288
IPullRequestModel pullRequest,
289289
string fileName,
290-
string fileSha)
290+
string fileSha,
291+
bool isPullRequestBranchCheckedOut)
291292
{
292293
return Observable.Defer(async () =>
293294
{
@@ -300,7 +301,9 @@ public IObservable<Tuple<string, string>> ExtractDiffFiles(
300301

301302
// The right file - if it comes from a fork - may not be fetched so fall back to
302303
// getting the file contents from the model service.
303-
var right = await GetFileFromRepositoryOrApi(repository, repo, modelService, pullRequest.Head.Sha, fileName, fileSha);
304+
var right = isPullRequestBranchCheckedOut ?
305+
Path.Combine(repository.LocalPath, fileName) :
306+
await GetFileFromRepositoryOrApi(repository, repo, modelService, pullRequest.Head.Sha, fileName, fileSha);
304307

305308
if (left == null)
306309
{

src/GitHub.App/ViewModels/PullRequestDetailViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public async Task Load(IPullRequestModel pullRequest)
358358
public Task<Tuple<string, string>> ExtractDiffFiles(IPullRequestFileNode file)
359359
{
360360
var path = Path.Combine(file.DirectoryPath, file.FileName);
361-
return pullRequestsService.ExtractDiffFiles(repository, modelService, model, path, file.Sha).ToTask();
361+
return pullRequestsService.ExtractDiffFiles(repository, modelService, model, path, file.Sha, IsCheckedOut).ToTask();
362362
}
363363

364364
/// <summary>

src/GitHub.Exports.Reactive/Services/IPullRequestService.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,18 @@ IObservable<string> ExtractFile(
120120
/// <param name="pullRequest">The pull request details.</param>
121121
/// <param name="fileName">The filename relative to the repository root.</param>
122122
/// <param name="fileSha">The SHA of the file in the pull request.</param>
123-
/// <returns>The filenames of the left and right files for the diff.</returns>
123+
/// <param name="isPullRequestBranchCheckedOut">
124+
/// Whether the pull request branch is currently checked out. If so the right file returned
125+
/// will be the path to the file in the working directory.
126+
/// </param>
127+
/// <returns>The paths of the left and right files for the diff.</returns>
124128
IObservable<Tuple<string, string>> ExtractDiffFiles(
125129
ILocalRepositoryModel repository,
126130
IModelService modelService,
127131
IPullRequestModel pullRequest,
128132
string fileName,
129-
string fileSha);
133+
string fileSha,
134+
bool isPullRequestBranchCheckedOut);
130135

131136
/// <summary>
132137
/// Remotes all unused remotes that were created by GitHub for Visual Studio to track PRs

src/GitHub.Exports.Reactive/ViewModels/IPullRequestDetailViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public interface IPullRequestDetailViewModel : IViewModel, IHasBusy
7979
/// </summary>
8080
string TargetBranchDisplayName { get; }
8181

82+
/// <summary>
83+
/// Gets a value indicating whether the pull request branch is checked out.
84+
/// </summary>
85+
bool IsCheckedOut { get; }
86+
8287
/// <summary>
8388
/// Gets a value indicating whether the pull request comes from a fork.
8489
/// </summary>

src/GitHub.VisualStudio/UI/Views/PullRequestDetailView.xaml.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,24 @@ async Task DoDiffFile(IPullRequestFileNode file)
8787
var rightLabel = $"{file.FileName};PR {ViewModel.Model.Number}";
8888
var caption = $"Diff - {file.FileName}";
8989
var tooltip = $"{leftLabel}\nvs.\n{rightLabel}";
90+
var options = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_DetectBinaryFiles |
91+
__VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;
92+
93+
if (!ViewModel.IsCheckedOut)
94+
{
95+
options |= __VSDIFFSERVICEOPTIONS.VSDIFFOPT_RightFileIsTemporary;
96+
}
9097

9198
Services.DifferenceService.OpenComparisonWindow2(
92-
fileNames.Item1,
93-
fileNames.Item2,
94-
caption,
95-
tooltip,
96-
leftLabel,
97-
rightLabel,
98-
string.Empty,
99-
string.Empty,
100-
(int)(__VSDIFFSERVICEOPTIONS.VSDIFFOPT_DetectBinaryFiles |
101-
__VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary |
102-
__VSDIFFSERVICEOPTIONS.VSDIFFOPT_RightFileIsTemporary));
99+
fileNames.Item1,
100+
fileNames.Item2,
101+
caption,
102+
tooltip,
103+
leftLabel,
104+
rightLabel,
105+
string.Empty,
106+
string.Empty,
107+
(uint)options);
103108
}
104109
catch (Exception e)
105110
{

0 commit comments

Comments
 (0)