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

Commit 637fd92

Browse files
authored
Merge branch 'master' into fixes/1240-nullref-diffservice
2 parents 8f96355 + 6706649 commit 637fd92

File tree

8 files changed

+70
-39
lines changed

8 files changed

+70
-39
lines changed

src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public PullRequestDetailViewModelDesigner()
6161
var repositoriesDir = new PullRequestDirectoryNode("Repositories");
6262
var itrackingBranch = new PullRequestFileNode(repoPath, @"GitHub\Models\ITrackingBranch.cs", "abc", PullRequestFileStatus.Modified, null);
6363
var oldBranchModel = new PullRequestFileNode(repoPath, @"GitHub\Models\OldBranchModel.cs", "abc", PullRequestFileStatus.Removed, null);
64-
var concurrentRepositoryConnection = new PullRequestFileNode(repoPath, @"GitHub\Repositories\ConcurrentRepositoryConnection.cs", "abc", PullRequestFileStatus.Added, "add");
64+
var concurrentRepositoryConnection = new PullRequestFileNode(repoPath, @"GitHub\Repositories\ConcurrentRepositoryConnection.cs", "abc", PullRequestFileStatus.Added, null);
6565

6666
repositoriesDir.Files.Add(concurrentRepositoryConnection);
6767
modelsDir.Directories.Add(repositoriesDir);

src/GitHub.App/ViewModels/GitHubPane/PullRequestDetailViewModel.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,12 @@ public Task<string> ExtractFile(IPullRequestFileNode file, bool head)
470470
{
471471
var relativePath = Path.Combine(file.DirectoryPath, file.FileName);
472472
var encoding = pullRequestsService.GetEncoding(LocalRepository, relativePath);
473+
474+
if (!head && file.OldPath != null)
475+
{
476+
relativePath = file.OldPath;
477+
}
478+
473479
return pullRequestsService.ExtractFile(LocalRepository, model, relativePath, head, encoding).ToTask();
474480
}
475481

@@ -527,7 +533,7 @@ async Task<IPullRequestDirectoryNode> CreateChangedFilesTree(IPullRequestModel p
527533
changedFile.FileName,
528534
changedFile.Sha,
529535
changedFile.Status,
530-
GetStatusDisplay(changedFile, changes));
536+
GetOldFileName(changedFile, changes));
531537

532538
var file = await Session.GetFile(changedFile.FileName);
533539
var fileCommentCount = file?.WhenAnyValue(x => x.InlineCommentThreads)
@@ -573,28 +579,15 @@ static string GetBranchDisplayName(bool isFromFork, string targetBranchLabel)
573579
}
574580
}
575581

576-
string GetStatusDisplay(IPullRequestFileModel file, TreeChanges changes)
582+
string GetOldFileName(IPullRequestFileModel file, TreeChanges changes)
577583
{
578-
switch (file.Status)
584+
if (file.Status == PullRequestFileStatus.Renamed)
579585
{
580-
case PullRequestFileStatus.Added:
581-
return Resources.AddedFileStatus;
582-
case PullRequestFileStatus.Renamed:
583-
var fileName = file.FileName.Replace("/", "\\");
584-
var change = changes?.Renamed.FirstOrDefault(x => x.Path == fileName);
585-
586-
if (change != null)
587-
{
588-
return Path.GetDirectoryName(change.OldPath) == Path.GetDirectoryName(change.Path) ?
589-
Path.GetFileName(change.OldPath) : change.OldPath;
590-
}
591-
else
592-
{
593-
return Resources.RenamedFileStatus;
594-
}
595-
default:
596-
return null;
586+
var fileName = file.FileName.Replace("/", "\\");
587+
return changes?.Renamed.FirstOrDefault(x => x.Path == fileName)?.OldPath;
597588
}
589+
590+
return null;
598591
}
599592

600593
IObservable<Unit> DoCheckout(object unused)

src/GitHub.App/ViewModels/GitHubPane/PullRequestFileNode.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using GitHub.App;
34
using GitHub.Extensions;
45
using GitHub.Models;
56
using ReactiveUI;
@@ -21,23 +22,43 @@ public class PullRequestFileNode : ReactiveObject, IPullRequestFileNode
2122
/// <param name="sha">The SHA of the file.</param>
2223
/// <param name="status">The way the file was changed.</param>
2324
/// <param name="statusDisplay">The string to display in the [message] box next to the filename.</param>
25+
/// <param name="oldPath">
26+
/// The old path of a moved/renamed file, relative to the repository. Should be null if the
27+
/// file was not moved/renamed.
28+
/// </param>
2429
public PullRequestFileNode(
2530
string repositoryPath,
2631
string path,
2732
string sha,
2833
PullRequestFileStatus status,
29-
string statusDisplay)
34+
string oldPath)
3035
{
3136
Guard.ArgumentNotEmptyString(repositoryPath, nameof(repositoryPath));
3237
Guard.ArgumentNotEmptyString(path, nameof(path));
3338
Guard.ArgumentNotEmptyString(sha, nameof(sha));
3439

3540
FileName = Path.GetFileName(path);
3641
DirectoryPath = Path.GetDirectoryName(path);
37-
DisplayPath = Path.Combine(Path.GetFileName(repositoryPath), DirectoryPath);
3842
Sha = sha;
3943
Status = status;
40-
StatusDisplay = statusDisplay;
44+
OldPath = oldPath;
45+
46+
if (status == PullRequestFileStatus.Added)
47+
{
48+
StatusDisplay = Resources.AddedFileStatus;
49+
}
50+
else if (status == PullRequestFileStatus.Renamed)
51+
{
52+
if (oldPath != null)
53+
{
54+
StatusDisplay = Path.GetDirectoryName(oldPath) == Path.GetDirectoryName(path) ?
55+
Path.GetFileName(oldPath) : oldPath;
56+
}
57+
else
58+
{
59+
StatusDisplay = Resources.RenamedFileStatus;
60+
}
61+
}
4162
}
4263

4364
/// <summary>
@@ -51,9 +72,9 @@ public PullRequestFileNode(
5172
public string DirectoryPath { get; }
5273

5374
/// <summary>
54-
/// Gets the path to display in the "Path" column of the changed files list.
75+
/// Gets the old path of a moved/renamed file, relative to the root of the repository.
5576
/// </summary>
56-
public string DisplayPath { get; }
77+
public string OldPath { get; }
5778

5879
/// <summary>
5980
/// Gets the SHA of the file.

src/GitHub.App/ViewModels/GitHubPane/PullRequestListViewModel.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public PullRequestListViewModel(
8888
.Where(x => PullRequests != null)
8989
.Subscribe(f => UpdateFilter(SelectedState, SelectedAssignee, SelectedAuthor, f));
9090

91+
this.WhenAnyValue(x => x.SelectedRepository)
92+
.Skip(1)
93+
.Subscribe(_ => ResetAndLoad());
94+
9195
OpenPullRequest = ReactiveCommand.Create();
9296
OpenPullRequest.Subscribe(DoOpenPullRequest);
9397
CreatePullRequest = ReactiveCommand.Create();
@@ -117,9 +121,9 @@ public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection
117121
new[] { remoteRepository.Parent, remoteRepository } :
118122
new[] { remoteRepository };
119123
SelectedState = States.FirstOrDefault(x => x.Name == listSettings.SelectedState) ?? States[0];
124+
125+
// Setting SelectedRepository will cause a Load().
120126
SelectedRepository = Repositories[0];
121-
WebUrl = repository.CloneUrl?.ToRepositoryUrl().Append("pulls");
122-
await Load();
123127
}
124128
finally
125129
{
@@ -321,6 +325,7 @@ void CreatePullRequests()
321325

322326
void ResetAndLoad()
323327
{
328+
WebUrl = SelectedRepository.CloneUrl?.ToRepositoryUrl().Append("pulls");
324329
CreatePullRequests();
325330
UpdateFilter(SelectedState, SelectedAssignee, SelectedAuthor, SearchQuery);
326331
Load().Forget();

src/GitHub.Exports.Reactive/ViewModels/GitHubPane/IPullRequestFileNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public interface IPullRequestFileNode : IPullRequestChangeNode
1010
string FileName { get; }
1111

1212
/// <summary>
13-
/// Gets the path to display in the "Path" column of the changed files list.
13+
/// Gets the old path of a moved/renamed file, relative to the root of the repository.
1414
/// </summary>
15-
string DisplayPath { get; }
15+
string OldPath { get; }
1616

1717
/// <summary>
1818
/// Gets the SHA of the file.

src/GitHub.VisualStudio/Views/GitHubPane/PullRequestDetailView.xaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,13 @@
317317
<ui:OcticonImage.Style>
318318
<Style TargetType="ui:OcticonImage" BasedOn="{StaticResource OcticonImage}">
319319
<Style.Triggers>
320-
<DataTrigger Binding="{Binding Status}" Value="Removed">
320+
<MultiDataTrigger>
321+
<MultiDataTrigger.Conditions>
322+
<Condition Binding="{Binding Status}" Value="Removed"/>
323+
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsSelected}" Value="False"/>
324+
</MultiDataTrigger.Conditions>
321325
<Setter Property="Foreground" Value="{DynamicResource GitHubDeletedFileIconBrush}"/>
322-
</DataTrigger>
326+
</MultiDataTrigger>
323327
</Style.Triggers>
324328
</Style>
325329
</ui:OcticonImage.Style>
@@ -329,9 +333,15 @@
329333
<Style TargetType="TextBlock">
330334
<Style.Triggers>
331335
<DataTrigger Binding="{Binding Status}" Value="Removed">
332-
<Setter Property="Foreground" Value="{DynamicResource GitHubDeletedFileBrush}"/>
333336
<Setter Property="TextDecorations" Value="Strikethrough"/>
334337
</DataTrigger>
338+
<MultiDataTrigger>
339+
<MultiDataTrigger.Conditions>
340+
<Condition Binding="{Binding Status}" Value="Removed"/>
341+
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsSelected}" Value="False"/>
342+
</MultiDataTrigger.Conditions>
343+
<Setter Property="Foreground" Value="{DynamicResource GitHubDeletedFileBrush}"/>
344+
</MultiDataTrigger>
335345
</Style.Triggers>
336346
</Style>
337347
</TextBlock.Style>

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ async Task DoDiffFile(IPullRequestFileNode file, bool workingDirectory)
123123
{
124124
try
125125
{
126-
var relativePath = System.IO.Path.Combine(file.DirectoryPath, file.FileName);
126+
var rightPath = System.IO.Path.Combine(file.DirectoryPath, file.FileName);
127+
var leftPath = file.OldPath ?? rightPath;
127128
var rightFile = workingDirectory ? ViewModel.GetLocalFilePath(file) : await ViewModel.ExtractFile(file, true);
128129
var leftFile = await ViewModel.ExtractFile(file, false);
129-
var fullPath = System.IO.Path.Combine(ViewModel.LocalRepository.LocalPath, relativePath);
130-
var leftLabel = $"{relativePath};{ViewModel.TargetBranchDisplayName}";
131-
var rightLabel = workingDirectory ? relativePath : $"{relativePath};PR {ViewModel.Model.Number}";
130+
var leftLabel = $"{leftPath};{ViewModel.TargetBranchDisplayName}";
131+
var rightLabel = workingDirectory ? rightPath : $"{rightPath};PR {ViewModel.Model.Number}";
132132
var caption = $"Diff - {file.FileName}";
133133
var options = __VSDIFFSERVICEOPTIONS.VSDIFFOPT_DetectBinaryFiles |
134134
__VSDIFFSERVICEOPTIONS.VSDIFFOPT_LeftFileIsTemporary;
@@ -161,11 +161,11 @@ async Task DoDiffFile(IPullRequestFileNode file, bool workingDirectory)
161161
var diffViewer = ((IVsDifferenceCodeWindow)docView).DifferenceViewer;
162162

163163
var session = ViewModel.Session;
164-
AddBufferTag(diffViewer.LeftView.TextBuffer, session, relativePath, DiffSide.Left);
164+
AddBufferTag(diffViewer.LeftView.TextBuffer, session, leftPath, DiffSide.Left);
165165

166166
if (!workingDirectory)
167167
{
168-
AddBufferTag(diffViewer.RightView.TextBuffer, session, relativePath, DiffSide.Right);
168+
AddBufferTag(diffViewer.RightView.TextBuffer, session, rightPath, DiffSide.Right);
169169
}
170170

171171
if (workingDirectory)

src/GitHub.VisualStudio/source.extension.vsixmanifest

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
</Metadata>
1414
<Installation AllUsers="true" Experimental="false">
1515
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[14.0,15.0]" />
16+
<InstallationTarget Version="[15.0,16.0)" Id="Microsoft.VisualStudio.IntegratedShell" />
1617
</Installation>
1718
<Dependencies>
1819
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
1920
<Dependency Id="Microsoft.VisualStudio.MPF.14.0" DisplayName="Visual Studio MPF 14.0" d:Source="Installed" Version="[14.0,]" />
21+
<Dependency Id="Microsoft.VisualStudio.TeamFoundation.TeamExplorer.Extensions" DisplayName="Team Explorer" d:Source="Installed" Version="[14.0,16.0)" />
2022
</Dependencies>
2123
<Assets>
2224
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />

0 commit comments

Comments
 (0)