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

Commit cef3e45

Browse files
Merge branch 'master' into fixes/popup-window-refactor
2 parents 2a25c70 + c7cf943 commit cef3e45

File tree

7 files changed

+135
-117
lines changed

7 files changed

+135
-117
lines changed

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ private async Task LogoutInternal(UriString host)
6161
public async Task CreateRepository(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization = null)
6262
{
6363
Guard.ArgumentNotNull(callback, "callback");
64-
await CreateRepositoryInternal(newRepository, callback, organization);
64+
try
65+
{
66+
var repository = await CreateRepositoryInternal(newRepository, organization);
67+
callback(repository, null);
68+
}
69+
catch (Exception e)
70+
{
71+
callback(null, e);
72+
}
6573
}
6674

6775
public async Task GetOrganizations(Action<IList<Organization>> callback)
@@ -71,6 +79,13 @@ public async Task GetOrganizations(Action<IList<Organization>> callback)
7179
callback(organizations);
7280
}
7381

82+
public async Task LoadKeychain(Action<bool> callback)
83+
{
84+
Guard.ArgumentNotNull(callback, "callback");
85+
var hasLoadedKeys = await LoadKeychainInternal();
86+
callback(hasLoadedKeys);
87+
}
88+
7489
public async Task GetCurrentUser(Action<Octokit.User> callback)
7590
{
7691
Guard.ArgumentNotNull(callback, "callback");
@@ -174,16 +189,15 @@ public async Task<bool> ContinueLoginAsync(LoginResult loginResult, Func<LoginRe
174189
return result.Code == LoginResultCodes.Success;
175190
}
176191

177-
private async Task CreateRepositoryInternal(NewRepository newRepository, Action<Octokit.Repository, Exception> callback, string organization)
192+
private async Task<Octokit.Repository> CreateRepositoryInternal(NewRepository newRepository, string organization)
178193
{
179194
try
180195
{
181196
logger.Trace("Creating repository");
182197

183-
if (!await EnsureKeychainLoaded())
198+
if (!await LoadKeychainInternal())
184199
{
185-
callback(null, new Exception("Keychain Not Loaded"));
186-
return;
200+
throw new InvalidOperationException("The keychain did not load");
187201
}
188202

189203
Octokit.Repository repository;
@@ -201,13 +215,12 @@ private async Task CreateRepositoryInternal(NewRepository newRepository, Action<
201215
}
202216

203217
logger.Trace("Created Repository");
204-
205-
callback(repository, null);
218+
return repository;
206219
}
207220
catch (Exception ex)
208221
{
209222
logger.Error(ex, "Error Creating Repository");
210-
callback(null, ex);
223+
throw;
211224
}
212225
}
213226

@@ -217,9 +230,9 @@ private async Task<IList<Organization>> GetOrganizationInternal()
217230
{
218231
logger.Trace("Getting Organizations");
219232

220-
if (!await EnsureKeychainLoaded())
233+
if (!await LoadKeychainInternal())
221234
{
222-
return null;
235+
return new List<Organization>();
223236
}
224237

225238
var organizations = await githubClient.Organization.GetAllForCurrent();
@@ -246,7 +259,7 @@ private async Task<IList<Organization>> GetOrganizationInternal()
246259
{
247260
logger.Trace("Getting Organizations");
248261

249-
if (!await EnsureKeychainLoaded())
262+
if (!await LoadKeychainInternal())
250263
{
251264
return null;
252265
}
@@ -262,27 +275,28 @@ private async Task<IList<Organization>> GetOrganizationInternal()
262275
return userCache;
263276
}
264277

265-
private async Task<bool> EnsureKeychainLoaded()
278+
private async Task<bool> LoadKeychainInternal()
266279
{
267-
logger.Trace("EnsureKeychainLoaded");
280+
logger.Trace("LoadKeychainInternal");
268281

269282
if (keychain.HasKeys)
270283
{
271284
if (!keychain.NeedsLoad)
272285
{
273-
logger.Trace("EnsureKeychainLoaded: Has keys does not need load");
286+
logger.Trace("LoadKeychainInternal: Has keys does not need load");
274287
return true;
275288
}
276289

277-
logger.Trace("EnsureKeychainLoaded: Loading");
290+
logger.Trace("LoadKeychainInternal: Loading");
278291

292+
//TODO: ONE_USER_LOGIN This assumes only ever one user can login
279293
var uriString = keychain.Connections.First().Host;
280294
var keychainAdapter = await keychain.Load(uriString);
281295

282296
return keychainAdapter.OctokitCredentials != Credentials.Anonymous;
283297
}
284298

285-
logger.Trace("EnsureKeychainLoaded: No keys to load");
299+
logger.Trace("LoadKeychainInternal: No keys to load");
286300

287301
return false;
288302
}

src/GitHub.Api/Application/IApiClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ interface IApiClient
1717
Task<bool> ValidateCredentials();
1818
Task Logout(UriString host);
1919
Task GetCurrentUser(Action<Octokit.User> callback);
20+
Task LoadKeychain(Action<bool> callback);
2021
}
2122
}

src/GitHub.Api/Git/Tasks/GitCommitTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public GitCommitTask(string message, string body,
1515
Guard.ArgumentNotNullOrWhiteSpace(message, "message");
1616

1717
Name = TaskName;
18-
arguments = "commit ";
18+
arguments = "-c i18n.commitencoding=utf8 commit ";
1919
arguments += String.Format(" -m \"{0}\"", message);
2020
if (!String.IsNullOrEmpty(body))
2121
arguments += String.Format(" -m \"{0}\"", body);

src/GitHub.Api/Git/Tasks/GitLogTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public GitLogTask(IGitObjectFactory gitObjectFactory,
1515

1616
public override string ProcessArguments
1717
{
18-
get { return @"log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status"; }
18+
get { return @"-c i18n.logoutputencoding=utf8 -c core.quotepath=false log --pretty=format:""%H%n%P%n%aN%n%aE%n%aI%n%cN%n%cE%n%cI%n%B---GHUBODYEND---"" --name-status"; }
1919
}
2020
}
2121
}

src/GitHub.Api/Git/Tasks/GitStatusTask.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public GitStatusTask(IGitObjectFactory gitObjectFactory,
1515

1616
public override string ProcessArguments
1717
{
18-
get { return "status -b -u --ignored --porcelain"; }
18+
get { return "-c i18n.logoutputencoding=utf8 -c core.quotepath=false status -b -u --ignored --porcelain"; }
1919
}
2020
public override TaskAffinity Affinity { get { return TaskAffinity.Exclusive; } }
2121
}

0 commit comments

Comments
 (0)