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

Commit ab8e274

Browse files
committed
Merge pull request #161 from github/shana/update-libgit2sharp
Bump libgit2sharp and fix broken Publish
2 parents 11e9f8d + 32fd475 commit ab8e274

File tree

15 files changed

+181
-52
lines changed

15 files changed

+181
-52
lines changed

GitHubVS.sln

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.23023.0
4+
VisualStudioVersion = 14.0.24720.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.VisualStudio", "src\GitHub.VisualStudio\GitHub.VisualStudio.csproj", "{11569514-5AE5-4B5B-92A2-F10B0967DE5F}"
77
EndProject
@@ -202,8 +202,8 @@ Global
202202
{4A84E568-CA86-4510-8CD0-90D3EF9B65F9}.Release|Any CPU.Build.0 = Release|Any CPU
203203
{4A84E568-CA86-4510-8CD0-90D3EF9B65F9}.Release|x86.ActiveCfg = Release|Any CPU
204204
{4A84E568-CA86-4510-8CD0-90D3EF9B65F9}.Release|x86.Build.0 = Release|Any CPU
205-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.ActiveCfg = Release|Any CPU
206-
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.Build.0 = Release|Any CPU
205+
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
206+
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|Any CPU.Build.0 = Debug|Any CPU
207207
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|x86.ActiveCfg = Debug|Any CPU
208208
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Debug|x86.Build.0 = Debug|Any CPU
209209
{EE6ED99F-CB12-4683-B055-D28FC7357A34}.Publish|Any CPU.ActiveCfg = Release|Any CPU

lib/LibGit2Sharp.dll

-363 KB
Binary file not shown.

src/CredentialManagement/Credential.cs

+15-18
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,31 @@ static Credential()
3131
}
3232
}
3333

34-
public Credential() : this(null, null, null)
35-
{
36-
}
34+
public Credential() : this(null, (string)null)
35+
{}
3736

38-
public Credential([AllowNull]string username) : this(username, null, null)
39-
{
40-
}
41-
42-
public Credential([AllowNull]string username, [AllowNull]string password)
43-
: this(username, password, null, CredentialType.Generic)
44-
{
45-
}
46-
47-
public Credential([AllowNull]string username, [AllowNull]string password, [AllowNull]string target)
48-
: this(username, password, target, CredentialType.Generic)
37+
public Credential(
38+
[AllowNull]string username,
39+
[AllowNull]SecureString password,
40+
[AllowNull]string target = null)
4941
{
42+
Username = username;
43+
SecurePassword = password;
44+
Target = target;
45+
Type = CredentialType.Generic;
46+
PersistenceType = PersistenceType.LocalComputer;
47+
_lastWriteTime = DateTime.MinValue;
5048
}
5149

5250
public Credential(
5351
[AllowNull]string username,
5452
[AllowNull]string password,
55-
[AllowNull]string target,
56-
[AllowNull]CredentialType type)
53+
[AllowNull]string target = null)
5754
{
5855
Username = username;
5956
Password = password;
6057
Target = target;
61-
Type = type;
58+
Type = CredentialType.Generic;
6259
PersistenceType = PersistenceType.Session;
6360
_lastWriteTime = DateTime.MinValue;
6461
}
@@ -353,4 +350,4 @@ static void ValidatePasswordLength(byte[] passwordBytes)
353350
}
354351
}
355352
}
356-
}
353+
}

src/GitHub.App/Caches/CredentialCache.cs

+55-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Akavache;
99
using GitHub.Helpers;
1010
using GitHub.Authentication.CredentialManagement;
11+
using System.Security;
1112

1213
namespace GitHub.Caches
1314
{
@@ -32,7 +33,6 @@ public IObservable<byte[]> Get(string key)
3233
using (var credential = new Credential())
3334
{
3435
credential.Target = keyHost;
35-
credential.Type = CredentialType.Generic;
3636
if (credential.Load())
3737
return Observable.Return(Encoding.Unicode.GetBytes(credential.Password));
3838
}
@@ -79,15 +79,33 @@ public IObservable<Unit> Vacuum()
7979
throw new NotImplementedException();
8080
}
8181

82-
// TODO: Use SecureString
8382
public IObservable<Unit> InsertObject<T>(string key, T value, DateTimeOffset? absoluteExpiration = default(DateTimeOffset?))
8483
{
8584
if (disposed) return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("CredentialCache");
8685

87-
var values = value as Tuple<string, string>;
88-
if (values == null)
89-
return ExceptionHelper.ObservableThrowInvalidOperationException<Unit>(key);
86+
if (value is Tuple<string, string>)
87+
return InsertTuple(key, value as Tuple<string, string>);
88+
if (value is Tuple<string, SecureString>)
89+
return InsertTuple(key, value as Tuple<string, SecureString>);
9090

91+
return ExceptionHelper.ObservableThrowInvalidOperationException<Unit>(key);
92+
}
93+
94+
static IObservable<Unit> InsertTuple(string key, Tuple<string, string> values)
95+
{
96+
var keyGit = GetKeyGit(key);
97+
if (!SaveKey(keyGit, values.Item1, values.Item2))
98+
return ExceptionHelper.ObservableThrowInvalidOperationException<Unit>(keyGit);
99+
100+
var keyHost = GetKeyHost(key);
101+
if (!SaveKey(keyHost, values.Item1, values.Item2))
102+
return ExceptionHelper.ObservableThrowInvalidOperationException<Unit>(keyGit);
103+
104+
return Observable.Return(Unit.Default);
105+
}
106+
107+
static IObservable<Unit> InsertTuple(string key, Tuple<string, SecureString> values)
108+
{
91109
var keyGit = GetKeyGit(key);
92110
if (!SaveKey(keyGit, values.Item1, values.Item2))
93111
return ExceptionHelper.ObservableThrowInvalidOperationException<Unit>(keyGit);
@@ -103,6 +121,8 @@ public IObservable<T> GetObject<T>(string key)
103121
{
104122
if (typeof(T) == typeof(Tuple<string, string>))
105123
return (IObservable<T>) GetTuple(key);
124+
if (typeof(T) == typeof(Tuple<string, SecureString>))
125+
return (IObservable<T>)GetSecureTuple(key);
106126
return ExceptionHelper.ObservableThrowInvalidOperationException<T>(key);
107127
}
108128

@@ -117,6 +137,17 @@ IObservable<Tuple<string, string>> GetTuple(string key)
117137
: ExceptionHelper.ObservableThrowKeyNotFoundException<Tuple<string, string>>(keyHost);
118138
}
119139

140+
IObservable<Tuple<string, SecureString>> GetSecureTuple(string key)
141+
{
142+
if (disposed) return ExceptionHelper.ObservableThrowObjectDisposedException<Tuple<string, SecureString>>("CredentialCache");
143+
144+
var keyHost = GetKeyHost(key);
145+
var ret = GetSecureKey(keyHost);
146+
return ret != null
147+
? Observable.Return(ret)
148+
: ExceptionHelper.ObservableThrowKeyNotFoundException<Tuple<string, SecureString>>(keyHost);
149+
}
150+
120151
public IObservable<IEnumerable<T>> GetAllObjects<T>()
121152
{
122153
throw new NotImplementedException();
@@ -188,8 +219,14 @@ static bool SaveKey(string key, string user, string pwd)
188219
{
189220
using (var credential = new Credential(user, pwd, key))
190221
{
191-
credential.Type = CredentialType.Generic;
192-
credential.PersistenceType = PersistenceType.LocalComputer;
222+
return credential.Save();
223+
}
224+
}
225+
226+
static bool SaveKey(string key, string user, SecureString pwd)
227+
{
228+
using (var credential = new Credential(user, pwd, key))
229+
{
193230
return credential.Save();
194231
}
195232
}
@@ -199,13 +236,23 @@ static Tuple<string, string> GetKey(string key)
199236
using (var credential = new Credential())
200237
{
201238
credential.Target = key;
202-
credential.Type = CredentialType.Generic;
203239
return credential.Load()
204240
? new Tuple<string, string>(credential.Username, credential.Password)
205241
: null;
206242
}
207243
}
208244

245+
static Tuple<string, SecureString> GetSecureKey(string key)
246+
{
247+
using (var credential = new Credential())
248+
{
249+
credential.Target = key;
250+
return credential.Load()
251+
? new Tuple<string, SecureString>(credential.Username, credential.SecurePassword)
252+
: null;
253+
}
254+
}
255+
209256
bool disposed;
210257
void Dispose(bool disposing)
211258
{

src/GitHub.App/GitHub.App.csproj

+7-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151
<DelaySign>false</DelaySign>
5252
</PropertyGroup>
5353
<ItemGroup>
54-
<Reference Include="LibGit2Sharp, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
55-
<HintPath>..\..\lib\LibGit2Sharp.dll</HintPath>
56-
</Reference>
5754
<Reference Include="Microsoft.TeamFoundation.Git.Controls, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
5855
<HintPath>..\..\lib\Microsoft.TeamFoundation.Git.Controls.dll</HintPath>
5956
<Private>False</Private>
@@ -138,6 +135,8 @@
138135
<DependentUpon>Resources.resx</DependentUpon>
139136
</Compile>
140137
<Compile Include="Services\AvatarProvider.cs" />
138+
<Compile Include="Services\GitHubCredentialProvider.cs" />
139+
<Compile Include="Services\IGitHubCredentialProvider.cs" />
141140
<Compile Include="Services\ImageDownloader.cs" />
142141
<Compile Include="Services\GitClient.cs" />
143142
<Compile Include="Services\ModelService.cs" />
@@ -240,6 +239,11 @@
240239
<Project>{252ce1c2-027a-4445-a3c2-e4d6c80a935a}</Project>
241240
<Name>Splat-Net45</Name>
242241
</ProjectReference>
242+
<ProjectReference Include="..\..\submodules\libgit2sharp\LibGit2Sharp\LibGit2Sharp.csproj">
243+
<Project>{EE6ED99F-CB12-4683-B055-D28FC7357A34}</Project>
244+
<Name>LibGit2Sharp</Name>
245+
<Private>False</Private>
246+
</ProjectReference>
243247
<ProjectReference Include="..\CredentialManagement\CredentialManagement.csproj">
244248
<Project>{41a47c5b-c606-45b4-b83c-22b9239e4da0}</Project>
245249
<Name>CredentialManagement</Name>

src/GitHub.App/GlobalSuppressions.cs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[assembly: SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Scope = "member", Target = "GitHub.ViewModels.CreateRepoViewModel.#ResetState()")]
44
[assembly: SuppressMessage("Microsoft.Naming", "CA1703:ResourceStringsShouldBeSpelledCorrectly", MessageId = "Git", Scope = "resource", Target = "GitHub.Resources.resources")]
5+
[assembly: SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Scope = "member", Target = "GitHub.Caches.CredentialCache.#InsertObject`1(System.String,!!0,System.Nullable`1<System.DateTimeOffset>)")]
56
// This file is used by Code Analysis to maintain SuppressMessage
67
// attributes that are applied to this project.
78
// Project-level suppressions either have no target or are given

src/GitHub.App/Services/GitClient.cs

+12-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ namespace GitHub.Services
1111
[PartCreationPolicy(CreationPolicy.Shared)]
1212
public class GitClient : IGitClient
1313
{
14+
readonly PushOptions pushOptions;
15+
readonly FetchOptions fetchOptions;
16+
17+
[ImportingConstructor]
18+
public GitClient(IGitHubCredentialProvider credentialProvider)
19+
{
20+
pushOptions = new PushOptions { CredentialsProvider = credentialProvider.HandleCredentials };
21+
fetchOptions = new FetchOptions { CredentialsProvider = credentialProvider.HandleCredentials };
22+
}
23+
1424
public IObservable<Unit> Push(IRepository repository, string branchName, string remoteName)
1525
{
1626
Guard.ArgumentNotEmptyString(branchName, nameof(branchName));
@@ -21,7 +31,7 @@ public IObservable<Unit> Push(IRepository repository, string branchName, string
2131
if (repository.Head?.Commits != null && repository.Head.Commits.Any())
2232
{
2333
var remote = repository.Network.Remotes[remoteName];
24-
repository.Network.Push(remote, "HEAD", @"refs/heads/" + branchName);
34+
repository.Network.Push(remote, "HEAD", @"refs/heads/" + branchName, pushOptions);
2535
}
2636
return Observable.Return(Unit.Default);
2737
});
@@ -34,7 +44,7 @@ public IObservable<Unit> Fetch(IRepository repository, string remoteName)
3444
return Observable.Defer(() =>
3545
{
3646
var remote = repository.Network.Remotes[remoteName];
37-
repository.Network.Fetch(remote);
47+
repository.Network.Fetch(remote, fetchOptions);
3848
return Observable.Return(Unit.Default);
3949
});
4050
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.ComponentModel.Composition;
3+
using System.Reactive.Linq;
4+
using System.Security;
5+
using Akavache;
6+
using GitHub.Caches;
7+
using GitHub.Primitives;
8+
using LibGit2Sharp;
9+
using NullGuard;
10+
11+
namespace GitHub.Services
12+
{
13+
[Export(typeof(IGitHubCredentialProvider))]
14+
[PartCreationPolicy(CreationPolicy.Shared)]
15+
class GitHubCredentialProvider : IGitHubCredentialProvider
16+
{
17+
readonly ISecureBlobCache secureCache = null;
18+
19+
[ImportingConstructor]
20+
public GitHubCredentialProvider(ISharedCache sharedCache)
21+
{
22+
secureCache = sharedCache.Secure;
23+
}
24+
25+
/// <summary>
26+
/// This is a callback from libgit2
27+
/// </summary>
28+
/// <returns></returns>
29+
public Credentials HandleCredentials([AllowNull]string url, [AllowNull]string username, SupportedCredentialTypes types)
30+
{
31+
if (url == null)
32+
return null; // wondering if we should return DefaultCredentials instead
33+
34+
var host = HostAddress.Create(url);
35+
return secureCache.GetObject<Tuple<string, SecureString>>("login:" + host.CredentialCacheKeyHost)
36+
.Select(CreateCredentials)
37+
.Catch(Observable.Return<Credentials>(null))
38+
.Wait();
39+
}
40+
41+
static Credentials CreateCredentials(Tuple<string, SecureString> data)
42+
{
43+
return new SecureUsernamePasswordCredentials
44+
{
45+
Username = data.Item1,
46+
Password = data.Item2
47+
};
48+
}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using LibGit2Sharp;
2+
3+
namespace GitHub.Services
4+
{
5+
public interface IGitHubCredentialProvider
6+
{
7+
Credentials HandleCredentials(string url, string username, SupportedCredentialTypes types);
8+
}
9+
}

src/GitHub.Exports.Reactive/GitHub.Exports.Reactive.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@
140140
<Name>Akavache_Net45</Name>
141141
<Private>False</Private>
142142
</ProjectReference>
143-
<Reference Include="LibGit2Sharp, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
144-
<HintPath>..\..\lib\LibGit2Sharp.dll</HintPath>
145-
</Reference>
143+
<ProjectReference Include="..\..\submodules\libgit2sharp\LibGit2Sharp\LibGit2Sharp.csproj">
144+
<Project>{ee6ed99f-cb12-4683-b055-d28fc7357a34}</Project>
145+
<Name>LibGit2Sharp</Name>
146+
</ProjectReference>
146147
<ProjectReference Include="..\..\submodules\octokit.net\Octokit\Octokit.csproj">
147148
<Project>{08dd4305-7787-4823-a53f-4d0f725a07f3}</Project>
148149
<Name>Octokit</Name>

src/GitHub.Exports/GitHub.Exports.csproj

+5-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
<Reference Include="envdte80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
5353
<EmbedInteropTypes>false</EmbedInteropTypes>
5454
</Reference>
55-
<Reference Include="LibGit2Sharp, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
56-
<HintPath>..\..\lib\LibGit2Sharp.dll</HintPath>
57-
</Reference>
5855
<Reference Include="Microsoft.TeamFoundation.Controls, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
5956
<HintPath>..\..\lib\\Microsoft.TeamFoundation.Controls.dll</HintPath>
6057
<Private>False</Private>
@@ -159,6 +156,11 @@
159156
<Project>{08dd4305-7787-4823-a53f-4d0f725a07f3}</Project>
160157
<Name>Octokit</Name>
161158
</ProjectReference>
159+
<ProjectReference Include="..\..\submodules\libgit2sharp\LibGit2Sharp\LibGit2Sharp.csproj">
160+
<Project>{EE6ED99F-CB12-4683-B055-D28FC7357A34}</Project>
161+
<Name>LibGit2Sharp</Name>
162+
<Private>True</Private>
163+
</ProjectReference>
162164
<ProjectReference Include="..\GitHub.Extensions\GitHub.Extensions.csproj">
163165
<Project>{6afe2e2d-6db0-4430-a2ea-f5f5388d2f78}</Project>
164166
<Name>GitHub.Extensions</Name>

src/GitHub.VisualStudio/GitHub.VisualStudio.csproj

+8-2
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@
301301
<IncludeInVSIX>true</IncludeInVSIX>
302302
</Content>
303303
<Content Include="Resources\preview_200x200.png">
304-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
304+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
305305
<IncludeInVSIX>true</IncludeInVSIX>
306306
</Content>
307307
<Content Include="Resources\logo_32x32%402x.png">
308-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
308+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
309309
<IncludeInVSIX>true</IncludeInVSIX>
310310
</Content>
311311
<Content Include="GitHub.VisualStudio.imagemanifest">
@@ -419,6 +419,12 @@
419419
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup;GetCopyToOutputDirectoryItems;DebugSymbolsProjectOutputGroup;</IncludeOutputGroupsInVSIX>
420420
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup;</IncludeOutputGroupsInVSIXLocalOnly>
421421
</ProjectReference>
422+
<ProjectReference Include="..\..\submodules\libgit2sharp\LibGit2Sharp\LibGit2Sharp.csproj">
423+
<Project>{ee6ed99f-cb12-4683-b055-d28fc7357a34}</Project>
424+
<Name>LibGit2Sharp</Name>
425+
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup%3bGetCopyToOutputDirectoryItems%3bDebugSymbolsProjectOutputGroup%3b</IncludeOutputGroupsInVSIX>
426+
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup%3b</IncludeOutputGroupsInVSIXLocalOnly>
427+
</ProjectReference>
422428
<ProjectReference Include="..\..\submodules\octokit.net\Octokit.Reactive\Octokit.Reactive.csproj">
423429
<Project>{674b69b8-0780-4d54-ae2b-c15821fa51cb}</Project>
424430
<Name>Octokit.Reactive</Name>

0 commit comments

Comments
 (0)