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

Commit b1e012a

Browse files
committed
Merge master into haacked/add-unit-tests
2 parents 8bba2b6 + ad6a715 commit b1e012a

22 files changed

+555
-83
lines changed

lib/LibGit2Sharp.dll

363 KB
Binary file not shown.

src/GitHub.App/Caches/CredentialCache.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class CredentialCache : ISecureBlobCache, IObjectBlobCache
1616
public IScheduler Scheduler { get; protected set; }
1717

1818
readonly AsyncSubject<Unit> shutdown = new AsyncSubject<Unit>();
19-
public IObservable<Unit> Shutdown { get { return shutdown; } }
19+
public IObservable<Unit> Shutdown => shutdown;
2020

2121
public IObservable<Unit> Flush()
2222
{
@@ -84,7 +84,7 @@ public IObservable<Unit> Vacuum()
8484
{
8585
if (disposed) return ExceptionHelper.ObservableThrowObjectDisposedException<Unit>("CredentialCache");
8686

87-
Tuple<string, string> values = value as Tuple<string, string>;
87+
var values = value as Tuple<string, string>;
8888
if (values == null)
8989
return ExceptionHelper.ObservableThrowInvalidOperationException<Unit>(key);
9090

@@ -112,9 +112,9 @@ IObservable<Tuple<string, string>> GetTuple(string key)
112112

113113
var keyHost = GetKeyHost(key);
114114
var ret = GetKey(keyHost);
115-
if (ret != null)
116-
return Observable.Return(ret);
117-
return ExceptionHelper.ObservableThrowKeyNotFoundException<Tuple<string, string>>(keyHost);
115+
return ret != null
116+
? Observable.Return(ret)
117+
: ExceptionHelper.ObservableThrowKeyNotFoundException<Tuple<string, string>>(keyHost);
118118
}
119119

120120
public IObservable<IEnumerable<T>> GetAllObjects<T>()
@@ -180,9 +180,7 @@ static bool DeleteKey(string key)
180180
using (var credential = new Credential())
181181
{
182182
credential.Target = key;
183-
if (!credential.Load())
184-
return false;
185-
return credential.Delete();
183+
return credential.Load() && credential.Delete();
186184
}
187185
}
188186

@@ -202,9 +200,9 @@ static Tuple<string, string> GetKey(string key)
202200
{
203201
credential.Target = key;
204202
credential.Type = CredentialType.Generic;
205-
if (credential.Load())
206-
return new Tuple<string, string>(credential.Username, credential.Password);
207-
return null;
203+
return credential.Load()
204+
? new Tuple<string, string>(credential.Username, credential.Password)
205+
: null;
208206
}
209207
}
210208

src/GitHub.App/GitHub.App.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
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>
5457
<Reference Include="Microsoft.TeamFoundation.Git.Controls, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
5558
<HintPath>..\..\lib\Microsoft.TeamFoundation.Git.Controls.dll</HintPath>
5659
<Private>False</Private>
@@ -209,10 +212,6 @@
209212
<Name>Akavache_Net45</Name>
210213
<Private>False</Private>
211214
</ProjectReference>
212-
<ProjectReference Include="..\..\submodules\libgit2sharp\LibGit2Sharp\LibGit2Sharp.csproj">
213-
<Project>{ee6ed99f-cb12-4683-b055-d28fc7357a34}</Project>
214-
<Name>LibGit2Sharp</Name>
215-
</ProjectReference>
216215
<ProjectReference Include="..\..\submodules\octokit.net\Octokit.Reactive\Octokit.Reactive.csproj">
217216
<Project>{674b69b8-0780-4d54-ae2b-c15821fa51cb}</Project>
218217
<Name>Octokit.Reactive</Name>

src/GitHub.App/ViewModels/LoginTabViewModel.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrows
4141

4242
Login.ThrownExceptions.Subscribe(ex =>
4343
{
44-
if (!ex.IsCriticalException())
44+
if (ex.IsCriticalException()) return;
45+
46+
log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri,
47+
UsernameOrEmail), ex);
48+
if (ex is Octokit.ForbiddenException)
49+
{
50+
ShowLogInFailedError = true;
51+
LoginFailedMessage = "Make sure to use your password and not a Personal Access token to log in.";
52+
}
53+
else
4554
{
46-
log.Info(string.Format(CultureInfo.InvariantCulture, "Error logging into '{0}' as '{1}'", BaseUri, UsernameOrEmail), ex);
4755
ShowConnectingToHostFailed = true;
4856
}
4957
});
@@ -64,13 +72,20 @@ protected LoginTabViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrows
6472
return Observable.Return(Unit.Default);
6573
});
6674
}
67-
protected IRepositoryHosts RepositoryHosts { get; private set; }
75+
protected IRepositoryHosts RepositoryHosts { get; }
6876
protected abstract Uri BaseUri { get; }
69-
public IReactiveCommand<Unit> SignUp { get; private set; }
77+
public IReactiveCommand<Unit> SignUp { get; }
7078

71-
public IReactiveCommand<AuthenticationResult> Login { get; private set; }
72-
public IReactiveCommand<Unit> Reset { get; private set; }
73-
public IReactiveCommand<Unit> NavigateForgotPassword { get; private set; }
79+
public IReactiveCommand<AuthenticationResult> Login { get; }
80+
public IReactiveCommand<Unit> Reset { get; }
81+
public IReactiveCommand<Unit> NavigateForgotPassword { get; }
82+
83+
string loginFailedMessage = "Check your username and password, then try again";
84+
public string LoginFailedMessage
85+
{
86+
get { return loginFailedMessage; }
87+
set { this.RaiseAndSetIfChanged(ref loginFailedMessage, value); }
88+
}
7489

7590
string usernameOrEmail;
7691
[AllowNull]

src/GitHub.App/ViewModels/LoginToGitHubForEnterpriseViewModel.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class LoginToGitHubForEnterpriseViewModel : LoginTabViewModel, ILoginToGi
2121
[ImportingConstructor]
2222
public LoginToGitHubForEnterpriseViewModel(IRepositoryHosts hosts, IVisualStudioBrowser browser) : base(hosts, browser)
2323
{
24-
enterpriseUrlValidator = ReactivePropertyValidator.For(this, x => x.EnterpriseUrl)
24+
EnterpriseUrlValidator = ReactivePropertyValidator.For(this, x => x.EnterpriseUrl)
2525
.IfNullOrEmpty("Please enter an Enterprise URL")
2626
.IfNotUri("Please enter a valid Enterprise URL")
2727
.IfGitHubDotComHost("Not an Enterprise server. Please enter an Enterprise URL");
@@ -55,24 +55,13 @@ public string EnterpriseUrl
5555
set { this.RaiseAndSetIfChanged(ref enterpriseUrl, value); }
5656
}
5757

58-
readonly ReactivePropertyValidator enterpriseUrlValidator;
59-
public ReactivePropertyValidator EnterpriseUrlValidator
60-
{
61-
get { return enterpriseUrlValidator; }
62-
}
58+
public ReactivePropertyValidator EnterpriseUrlValidator { get; }
6359

64-
protected override Uri BaseUri
65-
{
66-
get
67-
{
68-
return new Uri(EnterpriseUrl);
69-
}
70-
}
60+
protected override Uri BaseUri => new Uri(EnterpriseUrl);
7161

7262
public IReactiveCommand<Unit> NavigateLearnMore
7363
{
7464
get;
75-
private set;
7665
}
7766

7867
protected override async Task ResetValidation()

src/GitHub.App/ViewModels/LoginToGitHubViewModel.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ namespace GitHub.ViewModels
1515
[PartCreationPolicy(CreationPolicy.NonShared)]
1616
public class LoginToGitHubViewModel : LoginTabViewModel, ILoginToGitHubViewModel
1717
{
18-
readonly Uri baseUri;
19-
2018
[ImportingConstructor]
2119
public LoginToGitHubViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBrowser browser)
2220
: base(repositoryHosts, browser)
2321
{
24-
baseUri = HostAddress.GitHubDotComHostAddress.WebUri;
22+
BaseUri = HostAddress.GitHubDotComHostAddress.WebUri;
2523

2624
NavigatePricing = ReactiveCommand.CreateAsyncObservable(_ =>
2725
{
@@ -31,16 +29,13 @@ public LoginToGitHubViewModel(IRepositoryHosts repositoryHosts, IVisualStudioBro
3129
});
3230
}
3331

34-
public IReactiveCommand<Unit> NavigatePricing { get; private set; }
32+
public IReactiveCommand<Unit> NavigatePricing { get; }
3533

36-
protected override Uri BaseUri
37-
{
38-
get { return baseUri; }
39-
}
34+
protected override Uri BaseUri { get; }
4035

41-
protected override IObservable<AuthenticationResult> LogIn(object args)
42-
{
43-
return LogInToHost(HostAddress.GitHubDotComHostAddress);
44-
}
36+
protected override IObservable<AuthenticationResult> LogIn(object args)
37+
{
38+
return LogInToHost(HostAddress.GitHubDotComHostAddress);
4539
}
40+
}
4641
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,9 @@
138138
<Name>Akavache_Net45</Name>
139139
<Private>False</Private>
140140
</ProjectReference>
141-
<ProjectReference Include="..\..\submodules\libgit2sharp\LibGit2Sharp\LibGit2Sharp.csproj">
142-
<Project>{ee6ed99f-cb12-4683-b055-d28fc7357a34}</Project>
143-
<Name>LibGit2Sharp</Name>
144-
</ProjectReference>
141+
<Reference Include="LibGit2Sharp, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
142+
<HintPath>..\..\lib\LibGit2Sharp.dll</HintPath>
143+
</Reference>
145144
<ProjectReference Include="..\..\submodules\octokit.net\Octokit\Octokit.csproj">
146145
<Project>{08dd4305-7787-4823-a53f-4d0f725a07f3}</Project>
147146
<Name>Octokit</Name>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public interface ILoginToHostViewModel
5959
/// </summary>
6060
bool ShowLogInFailedError { get; }
6161

62+
/// <summary>
63+
/// The message to show if login failed.
64+
/// </summary>
65+
string LoginFailedMessage { get; }
66+
6267
/// <summary>
6368
/// Gets a command which, when invoked, resets all properties
6469
/// and validators.

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
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>
5558
<Reference Include="Microsoft.TeamFoundation.Controls, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
5659
<HintPath>..\..\lib\\Microsoft.TeamFoundation.Controls.dll</HintPath>
5760
<Private>False</Private>
@@ -136,10 +139,6 @@
136139
<Compile Include="ViewModels\IViewModel.cs" />
137140
</ItemGroup>
138141
<ItemGroup>
139-
<ProjectReference Include="..\..\submodules\libgit2sharp\LibGit2Sharp\LibGit2Sharp.csproj">
140-
<Project>{ee6ed99f-cb12-4683-b055-d28fc7357a34}</Project>
141-
<Name>LibGit2Sharp</Name>
142-
</ProjectReference>
143142
<ProjectReference Include="..\..\submodules\octokit.net\Octokit\Octokit.csproj">
144143
<Project>{08dd4305-7787-4823-a53f-4d0f725a07f3}</Project>
145144
<Name>Octokit</Name>

src/GitHub.Exports/Services/Services.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,10 @@ public static Repository GetRepoFromIGit(this IGitRepositoryInfo repoInfo)
166166
return null;
167167
return new Repository(repoPath);
168168
}
169+
170+
public static UriString GetUriFromRepository(this IGitRepositoryInfo repoInfo)
171+
{
172+
return repoInfo.GetRepoFromIGit()?.GetUri();
173+
}
169174
}
170175
}

0 commit comments

Comments
 (0)