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

Commit 97273c4

Browse files
author
Andreia Gaita
committed
Merge master into fixes/api-failure-switch-auth-view
2 parents e00c98c + 090f950 commit 97273c4

34 files changed

+189
-316
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ The GitHub for Unity extension brings [Git](https://git-scm.com/) and GitHub int
4747

4848
### Requirements
4949

50-
- Unity 5.4-5.6
51-
- We've only tested the extension so far on Unity 5.4 to 5.6. There's currently an blocker issue opened for 5.3 support, so we know it doesn't run there. There are some issues for 2017.x, so it may or may not run well on that version. Personal edition is fine.
50+
- Unity 5.4-2017.1
51+
- We've only tested the extension so far on Unity 5.4 to 2017.1. There's currently an blocker issue opened for 5.3 support, so we know it doesn't run there. There are some issues for 2017.2, so it may or may not run well on that version. Personal edition is fine.
5252
- Git and Git LFS 2.x
5353

5454
#### Git on macOS

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Threading;
54
using System.Threading.Tasks;
65
using Octokit;
76

@@ -28,9 +27,6 @@ public static IApiClient Create(UriString repositoryUrl, IKeychain keychain)
2827
private readonly IGitHubClient githubClient;
2928
private readonly ILoginManager loginManager;
3029

31-
string owner;
32-
bool? isEnterprise;
33-
3430
public ApiClient(UriString hostUrl, IKeychain keychain, IGitHubClient githubClient)
3531
{
3632
Guard.ArgumentNotNull(hostUrl, nameof(hostUrl));

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected void Initialize()
3939
Logging.TracingEnabled = UserSettings.Get(Constants.TraceLoggingKey, false);
4040
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
4141
Platform.Initialize(ProcessManager, TaskManager);
42-
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
42+
GitClient = new GitClient(Environment, ProcessManager, TaskManager);
4343
SetupMetrics();
4444
}
4545

@@ -127,7 +127,7 @@ public void RestartRepository()
127127
{
128128
if (Environment.RepositoryPath != null)
129129
{
130-
repositoryManager = Unity.RepositoryManager.CreateInstance(Platform, TaskManager, UsageTracker, GitClient, Environment.RepositoryPath);
130+
repositoryManager = Unity.RepositoryManager.CreateInstance(Platform, TaskManager, GitClient, Environment.RepositoryPath);
131131
repositoryManager.Initialize();
132132
Environment.Repository.Initialize(repositoryManager);
133133
repositoryManager.Start();

src/GitHub.Api/Events/RepositoryWatcher.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ class RepositoryWatcher : IRepositoryWatcher
3030
private readonly CancellationToken cancellationToken;
3131
private readonly NPath[] ignoredPaths;
3232
private readonly ManualResetEventSlim pauseEvent;
33-
private readonly bool disableNative;
3433
private NativeInterface nativeInterface;
3534
private bool running;
36-
private Task task;
3735
private int lastCountOfProcessedEvents = 0;
3836
private bool processingEvents;
3937
private readonly ManualResetEventSlim signalProcessingEventsDone = new ManualResetEventSlim(false);
@@ -68,8 +66,7 @@ public void Initialize()
6866

6967
try
7068
{
71-
if (!disableNative)
72-
nativeInterface = new NativeInterface(pathsRepositoryPath);
69+
nativeInterface = new NativeInterface(pathsRepositoryPath);
7370
}
7471
catch (Exception ex)
7572
{
@@ -79,12 +76,6 @@ public void Initialize()
7976

8077
public void Start()
8178
{
82-
if (disableNative)
83-
{
84-
Logger.Trace("Native interface is disabled");
85-
return;
86-
}
87-
8879
if (nativeInterface == null)
8980
{
9081
Logger.Warning("NativeInterface is null");
@@ -95,7 +86,7 @@ public void Start()
9586

9687
running = true;
9788
pauseEvent.Reset();
98-
task = Task.Factory.StartNew(WatcherLoop, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
89+
Task.Factory.StartNew(WatcherLoop, cancellationToken, TaskCreationOptions.None, TaskScheduler.Default);
9990
}
10091

10192
public void Stop()

src/GitHub.Api/Git/GitClient.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ITask<string> GetConfig(string key, GitConfigSource configSource,
2323
ITask<string> SetConfig(string key, string value, GitConfigSource configSource,
2424
IOutputProcessor<string> processor = null);
2525

26+
ITask<string[]> GetConfigUserAndEmail();
27+
2628
ITask<List<GitLock>> ListLocks(bool local,
2729
BaseOutputListProcessor<GitLock> processor = null);
2830

@@ -87,16 +89,13 @@ class GitClient : IGitClient
8789
{
8890
private readonly IEnvironment environment;
8991
private readonly IProcessManager processManager;
90-
private readonly ICredentialManager credentialManager;
9192
private readonly ITaskManager taskManager;
9293
private readonly CancellationToken cancellationToken;
9394

94-
public GitClient(IEnvironment environment, IProcessManager processManager,
95-
ICredentialManager credentialManager, ITaskManager taskManager)
95+
public GitClient(IEnvironment environment, IProcessManager processManager, ITaskManager taskManager)
9696
{
9797
this.environment = environment;
9898
this.processManager = processManager;
99-
this.credentialManager = credentialManager;
10099
this.taskManager = taskManager;
101100
this.cancellationToken = taskManager.Token;
102101
}
@@ -242,7 +241,7 @@ public ITask<Version> LfsVersion(IOutputProcessor<Version> processor = null)
242241

243242
public ITask<string> GetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null)
244243
{
245-
Logger.Trace("GetConfig");
244+
Logger.Trace("GetConfig: {0}", key);
246245

247246
return new GitConfigGetTask(key, configSource, cancellationToken, processor)
248247
.Configure(processManager);
@@ -256,6 +255,28 @@ public ITask<string> SetConfig(string key, string value, GitConfigSource configS
256255
.Configure(processManager);
257256
}
258257

258+
public ITask<string[]> GetConfigUserAndEmail()
259+
{
260+
string username = null;
261+
string email = null;
262+
263+
return GetConfig("user.name", GitConfigSource.User).Then((success, value) => {
264+
if (success)
265+
{
266+
username = value;
267+
}
268+
269+
}).Then(GetConfig("user.email", GitConfigSource.User).Then((success, value) => {
270+
if (success)
271+
{
272+
email = value;
273+
}
274+
})).Then(success => {
275+
Logger.Trace("user.name:{1} user.email:{2}", success, username, email);
276+
return new[] { username, email };
277+
});
278+
}
279+
259280
public ITask<List<GitLock>> ListLocks(bool local, BaseOutputListProcessor<GitLock> processor = null)
260281
{
261282
Logger.Trace("ListLocks");

src/GitHub.Api/Git/GitConfig.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,16 @@ public string GetString(string key)
216216
public int GetInt(string key)
217217
{
218218
var value = this[key];
219-
var result = 0;
220-
var success = int.TryParse(value, out result);
219+
int result = 0;
220+
int.TryParse(value, out result);
221221
return result;
222222
}
223223

224224
public float GetFloat(string key)
225225
{
226226
var value = this[key];
227-
var result = 0F;
228-
var success = float.TryParse(value, out result);
227+
float result = 0F;
228+
float.TryParse(value, out result);
229229
return result;
230230
}
231231

src/GitHub.Api/Git/GitCredentialManager.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ class GitCredentialManager : ICredentialManager
1111
private ICredential credential;
1212
private string credHelper = null;
1313

14-
private readonly IEnvironment environment;
1514
private readonly IProcessManager processManager;
1615
private readonly ITaskManager taskManager;
1716

18-
public GitCredentialManager(IEnvironment environment, IProcessManager processManager,
17+
public GitCredentialManager(IProcessManager processManager,
1918
ITaskManager taskManager)
2019
{
21-
this.environment = environment;
2220
this.processManager = processManager;
2321
this.taskManager = taskManager;
2422
}

src/GitHub.Api/Git/Repository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public ITask SetupRemote(string remote, string remoteUrl)
8585
public ITask<List<GitLogEntry>> Log()
8686
{
8787
if (repositoryManager == null)
88-
return new FuncListTask<GitLogEntry>(TaskHelpers.GetCompletedTask(new List<GitLogEntry>()));
88+
return new FuncListTask<GitLogEntry>(new NotReadyException().ToTask<List<GitLogEntry>>());
8989

9090
return repositoryManager.Log();
9191
}
@@ -123,7 +123,7 @@ public ITask Revert(string changeset)
123123
public ITask ListLocks()
124124
{
125125
if (repositoryManager == null)
126-
return new ActionTask(TaskExtensions.CompletedTask);
126+
return new ActionTask(new NotReadyException().ToTask<bool>());
127127
return repositoryManager.ListLocks(false);
128128
}
129129

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Threading;
54
using System.Threading.Tasks;
65

76
namespace GitHub.Unity
@@ -94,13 +93,11 @@ public RepositoryPathConfiguration(NPath repositoryPath)
9493

9594
class RepositoryManager : IRepositoryManager
9695
{
97-
private readonly CancellationToken cancellationToken;
9896
private readonly IGitConfig config;
9997
private readonly IGitClient gitClient;
10098
private readonly IPlatform platform;
10199
private readonly IRepositoryPathConfiguration repositoryPaths;
102100
private readonly ITaskManager taskManager;
103-
private readonly IUsageTracker usageTracker;
104101
private readonly IRepositoryWatcher watcher;
105102

106103
private bool isBusy;
@@ -119,23 +116,21 @@ class RepositoryManager : IRepositoryManager
119116
public event Action<string, string> OnRemoteBranchRemoved;
120117
public event Action<GitStatus> OnStatusUpdated;
121118

122-
public RepositoryManager(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker, IGitConfig gitConfig,
119+
public RepositoryManager(IPlatform platform, ITaskManager taskManager, IGitConfig gitConfig,
123120
IRepositoryWatcher repositoryWatcher, IGitClient gitClient,
124-
IRepositoryPathConfiguration repositoryPaths, CancellationToken cancellationToken)
121+
IRepositoryPathConfiguration repositoryPaths)
125122
{
126123
this.repositoryPaths = repositoryPaths;
127124
this.platform = platform;
128125
this.taskManager = taskManager;
129-
this.usageTracker = usageTracker;
130-
this.cancellationToken = cancellationToken;
131126
this.gitClient = gitClient;
132127
this.watcher = repositoryWatcher;
133128
this.config = gitConfig;
134129

135130
SetupWatcher();
136131
}
137132

138-
public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager taskManager, IUsageTracker usageTracker,
133+
public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager taskManager,
139134
IGitClient gitClient, NPath repositoryRoot)
140135
{
141136
var repositoryPathConfiguration = new RepositoryPathConfiguration(repositoryRoot);
@@ -144,8 +139,8 @@ public static RepositoryManager CreateInstance(IPlatform platform, ITaskManager
144139

145140
var repositoryWatcher = new RepositoryWatcher(platform, repositoryPathConfiguration, taskManager.Token);
146141

147-
return new RepositoryManager(platform, taskManager, usageTracker, gitConfig, repositoryWatcher,
148-
gitClient, repositoryPathConfiguration, taskManager.Token);
142+
return new RepositoryManager(platform, taskManager, gitConfig, repositoryWatcher,
143+
gitClient, repositoryPathConfiguration);
149144
}
150145

151146
public void Initialize()
@@ -318,16 +313,20 @@ public ITask UnlockFile(string file, bool force)
318313

319314
private void LoadGitUser()
320315
{
321-
var user = new User();
322-
GitClient.GetConfig("user.name", GitConfigSource.User)
323-
.Then((success, value) => user.Name = value).Then(
324-
GitClient.GetConfig("user.email", GitConfigSource.User)
325-
.Then((success, value) => user.Email = value))
326-
.Then(() => {
327-
Logger.Trace("OnGitUserLoaded: {0}", user);
328-
OnGitUserLoaded?.Invoke(user);
329-
})
330-
.Start();
316+
GitClient.GetConfigUserAndEmail()
317+
.Then((success, strings) => {
318+
var username = strings[0];
319+
var email = strings[1];
320+
321+
var user = new User {
322+
Name = username,
323+
Email = email
324+
};
325+
326+
Logger.Trace("OnGitUserLoaded: {0}", user);
327+
OnGitUserLoaded?.Invoke(user);
328+
329+
}).Start();
331330
}
332331

333332
private void SetupWatcher()

src/GitHub.Api/Helpers/SimpleJson.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ static class SimpleJson
517517

518518
private static readonly char[] EscapeTable;
519519
private static readonly char[] EscapeCharacters = new char[] { '"', '\\', '\b', '\f', '\n', '\r', '\t' };
520-
private static readonly string EscapeCharactersString = new string(EscapeCharacters);
521520

522521
static SimpleJson()
523522
{

0 commit comments

Comments
 (0)