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

Commit 2ba066f

Browse files
Combined function to retrieve git name and email
1 parent 5e02c39 commit 2ba066f

File tree

4 files changed

+54
-39
lines changed

4 files changed

+54
-39
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 23 additions & 0 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

@@ -256,6 +258,27 @@ public ITask<string> SetConfig(string key, string value, GitConfigSource configS
256258
.Configure(processManager);
257259
}
258260

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

src/GitHub.Api/Git/RepositoryManager.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,20 @@ public ITask UnlockFile(string file, bool force)
318318

319319
private void LoadGitUser()
320320
{
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();
321+
GitClient.GetConfigUserAndEmail()
322+
.Then((success, strings) => {
323+
var username = strings[0];
324+
var email = strings[1];
325+
326+
var user = new User {
327+
Name = username,
328+
Email = email
329+
};
330+
331+
Logger.Trace("OnGitUserLoaded: {0}", user);
332+
OnGitUserLoaded?.Invoke(user);
333+
334+
}).Start();
331335
}
332336

333337
private void SetupWatcher()

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,10 @@ private void CheckForUser()
138138
{
139139
isBusy = true;
140140

141-
string username = null;
142-
string email = null;
141+
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, strings) => {
142+
var username = strings[0];
143+
var email = strings[1];
143144

144-
GitClient.GetConfig("user.name", GitConfigSource.User).Then((success, value) => {
145-
Logger.Trace("Return success:{0} user.name", success, value);
146-
if (success)
147-
{
148-
username = value;
149-
}
150-
}).Then(GitClient.GetConfig("user.email", GitConfigSource.User).Then((success, value) => {
151-
Logger.Trace("Return success:{0} user.email", success, value);
152-
if (success)
153-
{
154-
email = value;
155-
}
156-
})).FinallyInUI((success, ex) => {
157145
Logger.Trace("Return success:{0} name:{1} email:{2}", success, username, email);
158146

159147
isBusy = false;

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,21 @@ private void MaybeUpdateData()
115115
{
116116
if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null)
117117
{
118-
var user = new User();
119-
GitClient.GetConfig("user.name", GitConfigSource.User)
120-
.Then((success, value) => user.Name = value).Then(
121-
GitClient.GetConfig("user.email", GitConfigSource.User)
122-
.Then((success, value) => user.Email = value))
123-
.FinallyInUI((success, ex) =>
118+
GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, strings) => {
119+
var username = strings[0];
120+
var email = strings[1];
121+
122+
if (success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email))
124123
{
125-
if (success && !String.IsNullOrEmpty(user.Name))
126-
{
127-
cachedUser = user;
128-
userDataHasChanged = true;
129-
Redraw();
130-
}
131-
})
132-
.Start();
124+
cachedUser = new User {
125+
Name = username,
126+
Email = email
127+
};
128+
129+
userDataHasChanged = true;
130+
Redraw();
131+
}
132+
}).Start();
133133
}
134134
}
135135

0 commit comments

Comments
 (0)