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

Commit bc5309f

Browse files
authored
Merge branch 'master' into fixes/1738-pr-details-scrollbar
2 parents df69e10 + 30ce6a2 commit bc5309f

File tree

9 files changed

+125
-38
lines changed

9 files changed

+125
-38
lines changed

src/GitHub.App/Services/GitClient.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,30 @@ public Task Fetch(IRepository repository, string remoteName)
9696

9797
public Task Fetch(IRepository repo, UriString cloneUrl, params string[] refspecs)
9898
{
99-
var httpsUrl = UriString.ToUriString(cloneUrl.ToRepositoryUrl());
99+
var httpsString = cloneUrl.ToRepositoryUrl().ToString();
100100

101-
var originRemote = repo.Network.Remotes[defaultOriginName];
102-
if (originRemote != null && originRemote.Url == httpsUrl)
101+
foreach (var remote in repo.Network.Remotes)
103102
{
104-
return Fetch(repo, defaultOriginName, refspecs);
103+
var remoteUrl = new UriString(remote.Url);
104+
if (!remoteUrl.IsHypertextTransferProtocol)
105+
{
106+
// Only match http urls
107+
continue;
108+
}
109+
110+
var remoteHttpsString = remoteUrl.ToRepositoryUrl().ToString();
111+
if (remoteHttpsString.Equals(httpsString, StringComparison.OrdinalIgnoreCase))
112+
{
113+
return Fetch(repo, defaultOriginName, refspecs);
114+
}
105115
}
106116

107117
return Task.Factory.StartNew(() =>
108118
{
109119
try
110120
{
111121
var tempRemoteName = cloneUrl.Owner + "-" + Guid.NewGuid();
112-
var remote = repo.Network.Remotes.Add(tempRemoteName, httpsUrl);
122+
var remote = repo.Network.Remotes.Add(tempRemoteName, httpsString);
113123
try
114124
{
115125
#pragma warning disable 0618 // TODO: Replace `Network.Fetch` with `Commands.Fetch`.

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
33
<Import Project="..\..\packages\LibGit2Sharp.NativeBinaries.1.0.164\build\LibGit2Sharp.NativeBinaries.props" Condition="Exists('..\..\packages\LibGit2Sharp.NativeBinaries.1.0.164\build\LibGit2Sharp.NativeBinaries.props')" />
4+
5+
<!-- When StartProgram is set to Visual Studio 2015 in .user file, install extension in the same version -->
6+
<Import Project="GitHub.VisualStudio.csproj.user" Condition=" Exists('GitHub.VisualStudio.csproj.user') " />
7+
<PropertyGroup Condition=" $(StartProgram.Contains('Microsoft Visual Studio 14.0')) ">
8+
<VisualStudioVersion>14.0</VisualStudioVersion>
9+
</PropertyGroup>
10+
411
<Import Project="..\..\packages\Microsoft.VisualStudio.Sdk.BuildTasks.14.0.14.0.215\build\Microsoft.VisualStudio.Sdk.BuildTasks.14.0.props" Condition="'$(VisualStudioVersion)' == '14.0' And Exists('..\..\packages\Microsoft.VisualStudio.Sdk.BuildTasks.14.0.14.0.215\build\Microsoft.VisualStudio.Sdk.BuildTasks.14.0.props')" />
512
<Import Project="..\..\packages\Microsoft.VSSDK.BuildTools.15.0.26201\build\Microsoft.VSSDK.BuildTools.props" Condition="'$(VisualStudioVersion)' == '15.0' And Exists('..\..\packages\Microsoft.VSSDK.BuildTools.15.0.26201\build\Microsoft.VSSDK.BuildTools.props')" />
613
<PropertyGroup>
@@ -27,7 +34,7 @@
2734
<RootNamespace>GitHub.VisualStudio</RootNamespace>
2835
<AssemblyName>GitHub.VisualStudio</AssemblyName>
2936
<StartAction>Program</StartAction>
30-
<StartProgram>$(DevEnvDir)\devenv.exe</StartProgram>
37+
<StartProgram Condition=" '$(StartProgram)' == '' ">$(DevEnvDir)\devenv.exe</StartProgram>
3138
<StartArguments>/rootsuffix Exp</StartArguments>
3239
<LangVersion>6</LangVersion>
3340
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
@@ -142,6 +149,12 @@
142149
<HintPath>..\..\packages\Microsoft.VisualStudio.Editor.14.3.25407\lib\net45\Microsoft.VisualStudio.Editor.dll</HintPath>
143150
<Private>True</Private>
144151
</Reference>
152+
<Reference Include="Microsoft.VisualStudio.ImageCatalog, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
153+
<HintPath>..\..\packages\Microsoft.VisualStudio.ImageCatalog.14.3.25407\lib\net45\Microsoft.VisualStudio.ImageCatalog.dll</HintPath>
154+
</Reference>
155+
<Reference Include="Microsoft.VisualStudio.Imaging, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
156+
<HintPath>..\..\packages\Microsoft.VisualStudio.Imaging.14.3.25407\lib\net45\Microsoft.VisualStudio.Imaging.dll</HintPath>
157+
</Reference>
145158
<Reference Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
146159
<EmbedInteropTypes>True</EmbedInteropTypes>
147160
<HintPath>..\..\packages\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.14.3.25407\lib\Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.dll</HintPath>
@@ -387,6 +400,8 @@
387400
<Compile Include="Views\Dialog\RepositoryRecloneView.xaml.cs">
388401
<DependentUpon>RepositoryRecloneView.xaml</DependentUpon>
389402
</Compile>
403+
<Compile Include="Views\GitHubPane\DirectoryIsExpandedToImageMonikerConverter.cs" />
404+
<Compile Include="Views\GitHubPane\FileNameToImageMonikerConverter.cs" />
390405
<Compile Include="Views\GitHubPane\LoggedOutView.xaml.cs">
391406
<DependentUpon>LoggedOutView.xaml</DependentUpon>
392407
</Compile>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.Globalization;
4+
using System.Windows.Data;
5+
using Microsoft.VisualStudio.Imaging;
6+
7+
namespace GitHub.VisualStudio.Views.GitHubPane
8+
{
9+
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Used in XAML")]
10+
internal sealed class DirectoryIsExpandedToImageMonikerConverter : IValueConverter
11+
{
12+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
13+
{
14+
return (bool)value ? KnownMonikers.FolderOpened : KnownMonikers.FolderClosed;
15+
}
16+
17+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
18+
{
19+
throw new NotImplementedException();
20+
}
21+
}
22+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Globalization;
5+
using System.Windows;
6+
using System.Windows.Data;
7+
using Microsoft.VisualStudio.Imaging.Interop;
8+
using Microsoft.VisualStudio.Shell;
9+
using Microsoft.VisualStudio.Shell.Interop;
10+
11+
namespace GitHub.VisualStudio.Views.GitHubPane
12+
{
13+
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Used in XAML")]
14+
internal sealed class FileNameToImageMonikerConverter : IValueConverter
15+
{
16+
private readonly IVsImageService2 imageService;
17+
18+
public FileNameToImageMonikerConverter()
19+
{
20+
imageService = (IVsImageService2)Package.GetGlobalService(typeof(SVsImageService));
21+
}
22+
23+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
24+
{
25+
// In design mode, imageService will be null
26+
if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
27+
return default(ImageMoniker);
28+
29+
return imageService.GetImageMonikerForFile((string)value);
30+
}
31+
32+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
33+
{
34+
throw new NotImplementedException();
35+
}
36+
}
37+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
xmlns:prop="clr-namespace:GitHub.VisualStudio.UI;assembly=GitHub.VisualStudio.UI"
99
xmlns:markdig="clr-namespace:Markdig.Wpf;assembly=Markdig.Wpf"
1010
xmlns:vsui="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0"
11+
xmlns:theming="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Imaging"
1112
Background="{DynamicResource GitHubVsToolWindowBackground}"
1213
Foreground="{DynamicResource GitHubVsWindowText}"
14+
theming:ImageThemingUtilities.ImageBackgroundColor="{Binding RelativeSource={RelativeSource Self}, Path=Background.Color}"
1315
DataContext="{Binding ViewModel}"
1416
d:DesignWidth="356"
1517
d:DesignHeight="800"

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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:ghfvs="https://github.com/github/VisualStudio"
7+
xmlns:local="clr-namespace:GitHub.VisualStudio.Views.GitHubPane"
78
xmlns:prop="clr-namespace:GitHub.VisualStudio.UI;assembly=GitHub.VisualStudio.UI"
9+
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
810
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
911
Name="root">
1012

@@ -47,10 +49,14 @@
4749
</Style>
4850
</TreeView.ItemContainerStyle>
4951
<TreeView.Resources>
52+
<local:DirectoryIsExpandedToImageMonikerConverter x:Key="DirectoryIsExpandedToImageMonikerConverter" />
53+
<local:FileNameToImageMonikerConverter x:Key="FileNameToImageMonikerConverter" />
54+
5055
<HierarchicalDataTemplate DataType="{x:Type ghfvs:PullRequestDirectoryNode}"
5156
ItemsSource="{Binding Children}">
5257
<StackPanel Orientation="Horizontal">
53-
<ghfvs:OcticonImage Icon="file_directory" Foreground="{DynamicResource GitHubDirectoryIconForeground}" Margin="0,0,0,2"/>
58+
<imaging:CrispImage Moniker="{Binding Converter={StaticResource DirectoryIsExpandedToImageMonikerConverter}, RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsExpanded}"
59+
Width="16" Height="16" Margin="0,0,0,2"/>
5460
<TextBlock Text="{Binding DirectoryName}" Margin="4 2" VerticalAlignment="Center"/>
5561
</StackPanel>
5662
</HierarchicalDataTemplate>
@@ -60,27 +66,8 @@
6066
Tag="{Binding DataContext, ElementName=root}"
6167
KeyboardNavigation.DirectionalNavigation="None">
6268

63-
<!--
64-
We need to change the color of the file icon when the file is deleted, but applying the style
65-
to OcticonImage directly borks the designer (see #1410). Work around this by applying the color
66-
to a parent control and let the foreground be inherited by the icon.
67-
-->
68-
<Decorator>
69-
<Decorator.Style>
70-
<Style TargetType="Decorator">
71-
<Style.Triggers>
72-
<MultiDataTrigger>
73-
<MultiDataTrigger.Conditions>
74-
<Condition Binding="{Binding Status}" Value="Removed"/>
75-
<Condition Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type TreeViewItem}}, Path=IsSelected}" Value="False"/>
76-
</MultiDataTrigger.Conditions>
77-
<Setter Property="TextBlock.Foreground" Value="{DynamicResource GitHubDeletedFileIconBrush}"/>
78-
</MultiDataTrigger>
79-
</Style.Triggers>
80-
</Style>
81-
</Decorator.Style>
82-
<ghfvs:OcticonImage Icon="file_code" Margin="0,0,0,2"/>
83-
</Decorator>
69+
<imaging:CrispImage Moniker="{Binding Converter={StaticResource FileNameToImageMonikerConverter}, Path=FileName}"
70+
Width="16" Height="16" Margin="0,0,0,2"/>
8471

8572
<TextBlock Text="{Binding FileName}" Margin="4 2" VerticalAlignment="Center">
8673
<TextBlock.Style>

src/GitHub.VisualStudio/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<package id="Microsoft.VisualStudio.ComponentModelHost" version="14.0.25424" targetFramework="net461" />
1010
<package id="Microsoft.VisualStudio.CoreUtility" version="14.3.25407" targetFramework="net461" />
1111
<package id="Microsoft.VisualStudio.Editor" version="14.3.25407" targetFramework="net461" />
12+
<package id="Microsoft.VisualStudio.ImageCatalog" version="14.3.25407" targetFramework="net461" />
13+
<package id="Microsoft.VisualStudio.Imaging" version="14.3.25407" targetFramework="net461" />
1214
<package id="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" version="14.3.25407" targetFramework="net461" />
1315
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6070" targetFramework="net461" />
1416
<package id="Microsoft.VisualStudio.Sdk.BuildTasks.14.0" version="14.0.215" targetFramework="net461" developmentDependency="true" />

src/GitHub.VisualStudio/source.extension.vsixmanifest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="GitHub.Exports.Reactive" Path="|GitHub.Exports.Reactive|" />
3030
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="GitHub.App" Path="|GitHub.App|" />
3131
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="GitHub.Services.Vssdk" Path="|GitHub.Services.Vssdk|" />
32-
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="GitHub.TeamFoundation.14" Path="|GitHub.TeamFoundation.14|" />
33-
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="GitHub.TeamFoundation.15" Path="|GitHub.TeamFoundation.15|" />
32+
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="GitHub.TeamFoundation.14" TargetVersion="[14.0,15.0)" Path="|GitHub.TeamFoundation.14|" />
33+
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="GitHub.TeamFoundation.15" TargetVersion="[15.0,16.0)" Path="|GitHub.TeamFoundation.15|" />
3434
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="GitHub.InlineReviewsPackage" Path="|GitHub.InlineReviews;PkgdefProjectOutputGroup|" />
3535
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="GitHub.StartPage" Path="|GitHub.StartPage;PkgdefProjectOutputGroup|" />
3636
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="GitHub.InlineReviews" Path="|GitHub.InlineReviews|" />

test/UnitTests/GitHub.App/Services/GitClientTests.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ public async Task FetchUsingHttps(string repoUrl, string expectFetchUrl)
208208
repo.Network.Remotes.Received(1).Add(Arg.Any<string>(), expectFetchUrl);
209209
}
210210

211-
[TestCase("https://github.com/owner/repo", "https://github.com/owner/repo", null)]
212-
[TestCase("https://github.com/fetch/repo", "https://github.com/origin/repo", "https://github.com/fetch/repo")]
213-
[TestCase("[email protected]:owner/repo", "[email protected]:owner/repo", "https://github.com/owner/repo")]
214-
public async Task UseOriginWhenPossible(string fetchUrl, string originUrl, string addUrl = null)
211+
[TestCase("https://github.com/owner/repo", "origin", "https://github.com/owner/repo", null)]
212+
[TestCase("https://github.com/fetch/repo", "origin", "https://github.com/origin/repo", "https://github.com/fetch/repo")]
213+
[TestCase("[email protected]:owner/repo", "origin", "[email protected]:owner/repo", "https://github.com/owner/repo", Description = "Only use http style urls")]
214+
[TestCase("https://github.com/jcansdale/repo", "jcansdale", "https://github.com/jcansdale/repo", null, Description = "Use existing remote")]
215+
[TestCase("https://github.com/jcansdale/repo.git", "jcansdale", "https://github.com/jcansdale/repo", null, Description = "Ignore trailing .git")]
216+
[TestCase("https://github.com/JCANSDALE/REPO", "jcansdale", "https://github.com/jcansdale/repo", null, Description = "Ignore different case")]
217+
public async Task UseExistingRemoteWhenPossible(string fetchUrl, string remoteName, string remoteUrl, string addUrl = null)
215218
{
216-
var remote = Substitute.For<Remote>();
217-
remote.Url.Returns(originUrl);
218-
var repo = Substitute.For<IRepository>();
219-
repo.Network.Remotes["origin"].Returns(remote);
219+
var repo = CreateRepository(remoteName, remoteUrl);
220220
var fetchUri = new UriString(fetchUrl);
221221
var refSpec = "refSpec";
222222
var gitClient = CreateGitClient();
@@ -232,6 +232,18 @@ public async Task UseOriginWhenPossible(string fetchUrl, string originUrl, strin
232232
repo.Network.Remotes.DidNotReceiveWithAnyArgs().Add(null, null);
233233
}
234234
}
235+
236+
static IRepository CreateRepository(string remoteName, string remoteUrl)
237+
{
238+
var remote = Substitute.For<Remote>();
239+
remote.Name.Returns(remoteName);
240+
remote.Url.Returns(remoteUrl);
241+
var remotes = new List<Remote> { remote };
242+
var repo = Substitute.For<IRepository>();
243+
repo.Network.Remotes[remoteName].Returns(remote);
244+
repo.Network.Remotes.GetEnumerator().Returns(_ => remotes.GetEnumerator());
245+
return repo;
246+
}
235247
}
236248

237249
public class TheGetPullRequestMergeBaseMethod : TestBaseClass

0 commit comments

Comments
 (0)