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

Commit 8447452

Browse files
Merge branch 'fixes/stop-watcher-for-commit' into enhancements/repository-watcher-refactor
# Conflicts: # src/GitHub.Api/Git/RepositoryManager.cs
2 parents 32641cc + d467e3e commit 8447452

File tree

4 files changed

+102
-34
lines changed

4 files changed

+102
-34
lines changed

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Threading;
45
using System.Threading.Tasks;
56

67
namespace GitHub.Unity
@@ -164,38 +165,38 @@ public int WaitForEvents()
164165

165166
public ITask CommitAllFiles(string message, string body)
166167
{
167-
var add = GitClient.AddAll();
168-
add.OnStart += t => IsBusy = true;
169-
return add
170-
.Then(GitClient.Commit(message, body))
171-
.Finally(() => IsBusy = false);
168+
var task = GitClient
169+
.AddAll()
170+
.Then(GitClient.Commit(message, body));
171+
172+
return HookupHandlers(task);
172173
}
173174

174175
public ITask CommitFiles(List<string> files, string message, string body)
175176
{
176-
var add = GitClient.Add(files);
177-
add.OnStart += t => IsBusy = true;
178-
return add
179-
.Then(GitClient.Commit(message, body))
180-
.Finally(() => IsBusy = false);
177+
var task = GitClient
178+
.Add(files)
179+
.Then(GitClient.Commit(message, body));
180+
181+
return HookupHandlers(task);
181182
}
182183

183184
public ITask Fetch(string remote)
184185
{
185186
var task = GitClient.Fetch(remote);
186-
return HookupHandlers(task);
187+
return HookupHandlers(task, false);
187188
}
188189

189190
public ITask Pull(string remote, string branch)
190191
{
191192
var task = GitClient.Pull(remote, branch);
192-
return HookupHandlers(task, true);
193+
return HookupHandlers(task);
193194
}
194195

195196
public ITask Push(string remote, string branch)
196197
{
197198
var task = GitClient.Push(remote, branch);
198-
return HookupHandlers(task);
199+
return HookupHandlers(task, false);
199200
}
200201

201202
public ITask Revert(string changeset)
@@ -207,7 +208,7 @@ public ITask Revert(string changeset)
207208
public ITask RemoteAdd(string remote, string url)
208209
{
209210
var task = GitClient.RemoteAdd(remote, url);
210-
HookupHandlers(task);
211+
task = HookupHandlers(task, false);
211212
if (!platform.Environment.IsWindows)
212213
{
213214
task.Then(_ => {
@@ -220,7 +221,7 @@ public ITask RemoteAdd(string remote, string url)
220221
public ITask RemoteRemove(string remote)
221222
{
222223
var task = GitClient.RemoteRemove(remote);
223-
HookupHandlers(task);
224+
task = HookupHandlers(task, false);
224225
if (!platform.Environment.IsWindows)
225226
{
226227
task.Then(_ => {
@@ -233,37 +234,37 @@ public ITask RemoteRemove(string remote)
233234
public ITask RemoteChange(string remote, string url)
234235
{
235236
var task = GitClient.RemoteChange(remote, url);
236-
return HookupHandlers(task);
237+
return HookupHandlers(task, false);
237238
}
238239

239240
public ITask SwitchBranch(string branch)
240241
{
241242
var task = GitClient.SwitchBranch(branch);
242-
return HookupHandlers(task, true);
243+
return HookupHandlers(task);
243244
}
244245

245246
public ITask DeleteBranch(string branch, bool deleteUnmerged = false)
246247
{
247248
var task = GitClient.DeleteBranch(branch, deleteUnmerged);
248-
return HookupHandlers(task);
249+
return HookupHandlers(task, false);
249250
}
250251

251252
public ITask CreateBranch(string branch, string baseBranch)
252253
{
253254
var task = GitClient.CreateBranch(branch, baseBranch);
254-
return HookupHandlers(task);
255+
return HookupHandlers(task, false);
255256
}
256257

257258
public ITask LockFile(string file)
258259
{
259260
var task = GitClient.Lock(file);
260-
return HookupHandlers(task);
261+
return HookupHandlers(task, false);
261262
}
262263

263264
public ITask UnlockFile(string file, bool force)
264265
{
265266
var task = GitClient.Unlock(file, force);
266-
return HookupHandlers(task);
267+
return HookupHandlers(task, false);
267268
}
268269

269270
public void UpdateGitLog()
@@ -279,17 +280,42 @@ public void UpdateGitLog()
279280
}).Start();
280281
}
281282

282-
public void UpdateGitStatus()
283+
private ITask<T> HookupHandlers<T>(ITask<T> task, bool disableWatcher = true, bool toggleBusyFlag = true)
283284
{
284-
var task = GitClient.Status();
285-
HookupHandlers(task);
286-
task.Then((success, status) =>
287-
{
288-
if (success)
289-
{
290-
GitStatusUpdated?.Invoke(status);
291-
}
292-
}).Start();
285+
return new ActionTask(CancellationToken.None, () => {
286+
if (toggleBusyFlag)
287+
{
288+
Logger.Trace("Starting Operation - Setting Busy Flag");
289+
IsBusy = true;
290+
}
291+
292+
if (disableWatcher)
293+
{
294+
Logger.Trace("Starting Operation - Disable Watcher");
295+
watcher.Stop();
296+
}
297+
})
298+
.Then(task)
299+
.Finally((success, exception, result) => {
300+
if (disableWatcher)
301+
{
302+
Logger.Trace("Ended Operation - Enable Watcher");
303+
watcher.Start();
304+
}
305+
306+
if (toggleBusyFlag)
307+
{
308+
Logger.Trace("Ended Operation - Clearing Busy Flag");
309+
IsBusy = false;
310+
}
311+
312+
if (success)
313+
{
314+
return result;
315+
}
316+
317+
throw exception;
318+
});
293319
}
294320

295321
public void UpdateLocks()

src/GitHub.Api/Helpers/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static class Constants
99
public const string UsageFile = "usage.json";
1010
public const string GitInstallPathKey = "GitInstallPath";
1111
public const string TraceLoggingKey = "EnableTraceLogging";
12-
public const string Iso8601Format = "o";
12+
public const string Iso8601Format = "yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz";
1313

1414
public static readonly Version MinimumGitVersion = new Version(2, 11, 0);
1515
public static readonly Version MinimumGitLfsVersion = new Version(2, 3, 4);

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ public override void OnEnable()
5151
userSettingsView.OnEnable();
5252
AttachHandlers(Repository);
5353

54-
Repository.CheckCurrentRemoteChangedEvent(lastCurrentRemoteChangedEvent);
55-
Repository.CheckLocksChangedEvent(lastLocksChangedEvent);
54+
if (Repository != null)
55+
{
56+
Repository.CheckCurrentRemoteChangedEvent(lastCurrentRemoteChangedEvent);
57+
Repository.CheckLocksChangedEvent(lastLocksChangedEvent);
58+
}
59+
5660
metricsHasChanged = true;
5761
}
5862

src/tests/TaskSystemIntegrationTests/Tests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,44 @@ public async Task ProcessReadsFromStandardInput()
108108
Assert.AreEqual(expectedOutput, output);
109109
}
110110

111+
[Test]
112+
public async Task ProcessOnStartOnEndTaskOrder()
113+
{
114+
var values = new List<string>();
115+
string process1Value = null;
116+
string process2Value = null;
117+
118+
var process1Task = new FirstNonNullLineProcessTask(Token, TestApp, @"-s 100 -d process1")
119+
.Configure(ProcessManager, true).Then((b, s) => {
120+
process1Value = s;
121+
values.Add(s);
122+
});
123+
124+
var process2Task = new FirstNonNullLineProcessTask(Token, TestApp, @"-s 100 -d process2")
125+
.Configure(ProcessManager, true).Then((b, s) => {
126+
process2Value = s;
127+
values.Add(s);
128+
});
129+
130+
var combinedTask = process1Task
131+
.Then(process2Task);
132+
133+
combinedTask.OnStart += task => {
134+
values.Add("OnStart");
135+
};
136+
137+
combinedTask.OnEnd += task => {
138+
values.Add("OnEnd");
139+
};
140+
141+
await combinedTask
142+
.StartAsAsync();
143+
144+
Assert.AreEqual(process1Value, "process1");
145+
Assert.AreEqual(process2Value, "process2");
146+
Assert.True(values.SequenceEqual(new []{ "process1", "OnStart", "process2", "OnEnd" }));
147+
}
148+
111149
[Test]
112150
public async Task ProcessReturningErrorThrowsException()
113151
{

0 commit comments

Comments
 (0)