Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 0d0f1d7

Browse files
Merge branch 'master' into fixes/break-up-git-add
# Conflicts: # src/GitHub.Api/Git/Tasks/GitAddTask.cs
2 parents d53292a + fd2a568 commit 0d0f1d7

File tree

73 files changed

+1144
-997
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1144
-997
lines changed

GitHub.Unity.sln.DotSettings

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
22
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=C_0023/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="C#"&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;CSUpdateFileHeader&gt;True&lt;/CSUpdateFileHeader&gt;&lt;CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="True" RemoveRedundantParentheses="True" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="True" ArrangeArgumentsStyle="True" /&gt;&lt;CSEnforceVarKeywordUsageSettings&gt;True&lt;/CSEnforceVarKeywordUsageSettings&gt;&lt;CSArrangeQualifiers&gt;True&lt;/CSArrangeQualifiers&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;/Profile&gt;</s:String>
3+
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=Relayout/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="Relayout"&gt;&lt;CSReorderTypeMembers&gt;True&lt;/CSReorderTypeMembers&gt;&lt;/Profile&gt;</s:String>
34
<s:String x:Key="/Default/CodeStyle/CodeCleanup/RecentlyUsedProfile/@EntryValue">C#</s:String>
45
<s:String x:Key="/Default/CodeStyle/CodeCleanup/SilentCleanupProfile/@EntryValue">C#</s:String>
56
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOR/@EntryValue">Required</s:String>
@@ -262,17 +263,6 @@
262263
&lt;ImplementsInterface Immediate="True" /&gt;&#xD;
263264
&lt;/Entry.SortBy&gt;&#xD;
264265
&lt;/Entry&gt;&#xD;
265-
&lt;Entry DisplayName="Other Static Methods" Priority="49"&gt;&#xD;
266-
&lt;Entry.Match&gt;&#xD;
267-
&lt;And&gt;&#xD;
268-
&lt;Kind Is="Method" /&gt;&#xD;
269-
&lt;Static /&gt;&#xD;
270-
&lt;/And&gt;&#xD;
271-
&lt;/Entry.Match&gt;&#xD;
272-
&lt;Entry.SortBy&gt;&#xD;
273-
&lt;Access /&gt;&#xD;
274-
&lt;/Entry.SortBy&gt;&#xD;
275-
&lt;/Entry&gt;&#xD;
276266
&lt;Entry DisplayName="Other Instance Methods" Priority="39"&gt;&#xD;
277267
&lt;Entry.Match&gt;&#xD;
278268
&lt;And&gt;&#xD;
@@ -300,6 +290,17 @@
300290
&lt;ImplementsInterface Immediate="True" /&gt;&#xD;
301291
&lt;/Entry.SortBy&gt;&#xD;
302292
&lt;/Entry&gt;&#xD;
293+
&lt;Entry DisplayName="Other Static Methods" Priority="49"&gt;&#xD;
294+
&lt;Entry.Match&gt;&#xD;
295+
&lt;And&gt;&#xD;
296+
&lt;Kind Is="Method" /&gt;&#xD;
297+
&lt;Static /&gt;&#xD;
298+
&lt;/And&gt;&#xD;
299+
&lt;/Entry.Match&gt;&#xD;
300+
&lt;Entry.SortBy&gt;&#xD;
301+
&lt;Access /&gt;&#xD;
302+
&lt;/Entry.SortBy&gt;&#xD;
303+
&lt;/Entry&gt;&#xD;
303304
&lt;Entry DisplayName="Dispose Implementation" Priority="100"&gt;&#xD;
304305
&lt;Entry.Match&gt;&#xD;
305306
&lt;Or&gt;&#xD;

common/GitHub.ruleset renamed to common/codeanalysis-full.ruleset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RuleSet Name="GitHub" Description="This ruleset only includes the rules we care about. I'll be adding new ones as we fix our codebase." ToolsVersion="14.0">
2+
<RuleSet Name="codeanalysis-full" Description="This ruleset only includes the rules we care about. I'll be adding new ones as we fix our codebase." ToolsVersion="14.0">
33
<IncludeAll Action="Warning" />
44
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
55
<Rule Id="CA1000" Action="None" />

common/codeanalysis-small.ruleset

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RuleSet Name="codeanalysis-small" Description="This ruleset only includes the rules we care about. I'll be adding new ones as we fix our codebase." ToolsVersion="14.0">
3+
<IncludeAll Action="Warning" />
4+
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
5+
<Rule Id="CA1000" Action="None" />
6+
<Rule Id="CA1002" Action="None" />
7+
<Rule Id="CA1006" Action="None" />
8+
<Rule Id="CA1014" Action="None" />
9+
<Rule Id="CA1017" Action="None" />
10+
<Rule Id="CA1020" Action="None" />
11+
<Rule Id="CA1021" Action="None" />
12+
<Rule Id="CA1024" Action="None" />
13+
<Rule Id="CA1026" Action="None" />
14+
<Rule Id="CA1030" Action="None" />
15+
<Rule Id="CA1031" Action="None" />
16+
<Rule Id="CA1033" Action="None" />
17+
<Rule Id="CA1034" Action="None" />
18+
<Rule Id="CA1045" Action="None" />
19+
<Rule Id="CA1051" Action="None" />
20+
<Rule Id="CA1054" Action="None" />
21+
<Rule Id="CA1055" Action="None" />
22+
<Rule Id="CA1056" Action="None" />
23+
<Rule Id="CA1062" Action="None" />
24+
<Rule Id="CA1063" Action="None" />
25+
<Rule Id="CA1303" Action="None" />
26+
<Rule Id="CA1305" Action="None" />
27+
<Rule Id="CA1307" Action="None" />
28+
<Rule Id="CA1401" Action="None" />
29+
<Rule Id="CA1402" Action="None" />
30+
<Rule Id="CA1403" Action="None" />
31+
<Rule Id="CA1405" Action="None" />
32+
<Rule Id="CA1406" Action="None" />
33+
<Rule Id="CA1407" Action="None" />
34+
<Rule Id="CA1408" Action="None" />
35+
<Rule Id="CA1409" Action="None" />
36+
<Rule Id="CA1410" Action="None" />
37+
<Rule Id="CA1411" Action="None" />
38+
<Rule Id="CA1412" Action="None" />
39+
<Rule Id="CA1413" Action="None" />
40+
<Rule Id="CA1501" Action="None" />
41+
<Rule Id="CA1502" Action="None" />
42+
<Rule Id="CA1506" Action="None" />
43+
<Rule Id="CA1701" Action="None" />
44+
<Rule Id="CA1702" Action="None" />
45+
<Rule Id="CA1703" Action="None" />
46+
<Rule Id="CA1704" Action="None" />
47+
<Rule Id="CA1707" Action="None" />
48+
<Rule Id="CA1708" Action="None" />
49+
<Rule Id="CA1709" Action="None" />
50+
<Rule Id="CA1710" Action="None" />
51+
<Rule Id="CA1711" Action="None" />
52+
<Rule Id="CA1712" Action="None" />
53+
<Rule Id="CA1713" Action="None" />
54+
<Rule Id="CA1714" Action="None" />
55+
<Rule Id="CA1715" Action="None" />
56+
<Rule Id="CA1716" Action="None" />
57+
<Rule Id="CA1717" Action="None" />
58+
<Rule Id="CA1719" Action="None" />
59+
<Rule Id="CA1720" Action="None" />
60+
<Rule Id="CA1721" Action="None" />
61+
<Rule Id="CA1722" Action="None" />
62+
<Rule Id="CA1724" Action="None" />
63+
<Rule Id="CA1725" Action="None" />
64+
<Rule Id="CA1726" Action="None" />
65+
<Rule Id="CA1800" Action="None" />
66+
<Rule Id="CA1801" Action="None" />
67+
<Rule Id="CA1810" Action="None" />
68+
<Rule Id="CA1811" Action="None" />
69+
<Rule Id="CA1812" Action="None" />
70+
<Rule Id="CA1822" Action="None" />
71+
<Rule Id="CA2000" Action="None" />
72+
<Rule Id="CA2118" Action="None" />
73+
<Rule Id="CA2122" Action="None" />
74+
<Rule Id="CA2200" Action="None" />
75+
<Rule Id="CA2201" Action="Warning" />
76+
<Rule Id="CA2204" Action="None" />
77+
<Rule Id="CA2210" Action="None" />
78+
<Rule Id="CA2211" Action="None" />
79+
<Rule Id="CA2213" Action="None" />
80+
<Rule Id="CA2227" Action="None" />
81+
<Rule Id="CA2235" Action="None" />
82+
<Rule Id="IDE001" Action="None" />
83+
84+
<!-- strings -->
85+
<Rule Id="CA1304" Action="None" />
86+
<Rule Id="CA1308" Action="None" />
87+
<Rule Id="CA1309" Action="None" />
88+
<Rule Id="CA1820" Action="None" />
89+
<Rule Id="CA1823" Action="None" />
90+
91+
<!-- serialization -->
92+
<Rule Id="CA2237" Action="None" />
93+
<Rule Id="CA1032" Action="None" />
94+
95+
<!-- link demand -->
96+
<Rule Id="CA2123" Action="None" />
97+
</Rules>
98+
<Rules AnalyzerId="Microsoft.CodeAnalysis.CSharp.Features" RuleNamespace="Microsoft.CodeAnalysis.CSharp.Features">
99+
<Rule Id="IDE0001" Action="None" />
100+
</Rules>
101+
</RuleSet>

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public async Task<bool> ContinueLoginAsync(LoginResult loginResult, Func<LoginRe
205205
// it'll throw if it's private or an enterprise instance requiring authentication
206206
catch (ApiException apiex)
207207
{
208-
if (!HostAddress.IsGitHubDotComUri(OriginalUrl.ToRepositoryUri()))
208+
if (!HostAddress.IsGitHubDotCom(OriginalUrl.ToRepositoryUri()))
209209
isEnterprise = apiex.IsGitHubApiException();
210210
}
211211
catch {}

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ abstract class ApplicationManagerBase : IApplicationManager
1111
{
1212
protected static ILogging Logger { get; } = Logging.GetLogger<IApplicationManager>();
1313

14-
private IEnvironment environment;
1514
private RepositoryManager repositoryManager;
1615

1716
public ApplicationManagerBase(SynchronizationContext synchronizationContext)
@@ -40,17 +39,18 @@ protected void Initialize()
4039
Logging.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
4140
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
4241
Platform.Initialize(ProcessManager, TaskManager);
42+
if (Environment.GitExecutablePath != null)
43+
{
44+
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
45+
}
46+
SetupMetrics();
4347
}
4448

4549
public virtual async Task Run(bool firstRun)
4650
{
4751
Logger.Trace("Run - CurrentDirectory {0}", NPath.CurrentDirectory);
4852

49-
if (Environment.GitExecutablePath != null)
50-
{
51-
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
52-
}
53-
else
53+
if (Environment.GitExecutablePath == null)
5454
{
5555
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
5656
Environment.GitExecutablePath = await DetermineGitExecutablePath();
@@ -70,9 +70,7 @@ public virtual async Task Run(bool firstRun)
7070
RestartRepository();
7171
InitializeUI();
7272

73-
new ActionTask(CancellationToken, SetupMetrics).Start();
7473
new ActionTask(new Task(() => LoadKeychain().Start())).Start();
75-
new ActionTask(CancellationToken, RunRepositoryManager).Start();
7674
}
7775

7876
public ITask InitializeRepository()
@@ -105,8 +103,7 @@ public ITask InitializeRepository()
105103
.Then(GitClient.Add(filesForInitialCommit))
106104
.Then(GitClient.Commit("Initial commit", null))
107105
.Then(RestartRepository)
108-
.ThenInUI(InitializeUI)
109-
.Then(RunRepositoryManager);
106+
.ThenInUI(InitializeUI);
110107
return task;
111108
}
112109

@@ -115,29 +112,15 @@ public void RestartRepository()
115112
Environment.InitializeRepository();
116113
if (Environment.RepositoryPath != null)
117114
{
118-
var repositoryPathConfiguration = new RepositoryPathConfiguration(Environment.RepositoryPath);
119-
var gitConfig = new GitConfig(repositoryPathConfiguration.DotGitConfig);
120-
121-
var repositoryWatcher = new RepositoryWatcher(Platform, repositoryPathConfiguration, TaskManager.Token);
122-
repositoryManager = new RepositoryManager(Platform, TaskManager, UsageTracker, gitConfig, repositoryWatcher,
123-
GitClient, repositoryPathConfiguration, TaskManager.Token);
124-
Environment.Repository = repositoryManager.Repository;
115+
repositoryManager = Unity.RepositoryManager.CreateInstance(Platform, TaskManager, UsageTracker, GitClient, Environment.RepositoryPath);
116+
Environment.Repository = new Repository(GitClient, repositoryManager, Environment.RepositoryPath);
117+
repositoryManager.Initialize();
118+
Environment.Repository.Initialize();
119+
repositoryManager.Start();
125120
Logger.Trace($"Got a repository? {Environment.Repository}");
126121
}
127122
}
128123

129-
private void RunRepositoryManager()
130-
{
131-
Logger.Trace("RunRepositoryManager");
132-
133-
if (Environment.RepositoryPath != null)
134-
{
135-
new ActionTask(repositoryManager.Initialize())
136-
.Then(repositoryManager.Start)
137-
.Start();;
138-
}
139-
}
140-
141124
private async Task LoadKeychain()
142125
{
143126
Logger.Trace("Loading Keychain");
@@ -212,7 +195,7 @@ protected virtual void Dispose(bool disposing)
212195
{
213196
if (disposed) return;
214197
disposed = true;
215-
if (TaskManager != null) TaskManager.Stop();
198+
if (TaskManager != null) TaskManager.Dispose();
216199
if (repositoryManager != null) repositoryManager.Dispose();
217200
}
218201
}

src/GitHub.Api/Authentication/ICredentialManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface ICredential : IDisposable
1414
interface ICredentialManager
1515
{
1616
Task<ICredential> Load(UriString host);
17-
Task Save(ICredential credential);
17+
Task Save(ICredential cred);
1818
Task Delete(UriString host);
1919
bool HasCredentials();
2020
ICredential CachedCredentials { get; }

src/GitHub.Api/Authentication/LoginManager.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public async Task<LoginResultData> Login(
9494
if (e is TwoFactorRequiredException)
9595
{
9696
result = LoginResultCodes.CodeRequired;
97-
logger.Debug("2FA TwoFactorAuthorizationException: {0} {1}", LoginResultCodes.CodeRequired, e.Message);
97+
logger.Trace("2FA TwoFactorAuthorizationException: {0} {1}", LoginResultCodes.CodeRequired, e.Message);
9898
}
9999
else
100100
{
@@ -166,21 +166,21 @@ public async Task<LoginResultData> ContinueLogin(LoginResultData loginResultData
166166
}
167167
catch (TwoFactorAuthorizationException e)
168168
{
169-
logger.Debug(e, "2FA TwoFactorAuthorizationException: {0} {1}", LoginResultCodes.CodeFailed, e.Message);
169+
logger.Trace(e, "2FA TwoFactorAuthorizationException: {0} {1}", LoginResultCodes.CodeFailed, e.Message);
170170

171171
return new LoginResultData(LoginResultCodes.CodeFailed, Localization.Wrong2faCode, client, host, newAuth);
172172
}
173173
catch (ApiValidationException e)
174174
{
175-
logger.Debug(e, "2FA ApiValidationException: {0}", e.Message);
175+
logger.Trace(e, "2FA ApiValidationException: {0}", e.Message);
176176

177177
var message = e.ApiError.FirstErrorMessageSafe();
178178
await keychain.Clear(host, false);
179179
return new LoginResultData(LoginResultCodes.Failed, message, host);
180180
}
181181
catch (Exception e)
182182
{
183-
logger.Debug(e, "Exception: {0}", e.Message);
183+
logger.Trace(e, "Exception: {0}", e.Message);
184184

185185
await keychain.Clear(host, false);
186186
return new LoginResultData(LoginResultCodes.Failed, e.Message, host);
@@ -257,7 +257,7 @@ bool EnterpriseWorkaround(UriString hostAddress, Exception e)
257257
// the failure, using basic authentication (with username and password) instead of trying
258258
// to get an authorization token.
259259
var apiException = e as ApiException;
260-
return !HostAddress.IsGitHubDotComUri(hostAddress.ToUri()) &&
260+
return !HostAddress.IsGitHubDotCom(hostAddress) &&
261261
(e is NotFoundException ||
262262
e is ForbiddenException ||
263263
apiException?.StatusCode == (HttpStatusCode)422);

0 commit comments

Comments
 (0)