diff --git a/src/GitHub.Api/Git/GitClient.cs b/src/GitHub.Api/Git/GitClient.cs index 12d9bf78b..9acef5286 100644 --- a/src/GitHub.Api/Git/GitClient.cs +++ b/src/GitHub.Api/Git/GitClient.cs @@ -23,7 +23,7 @@ ITask GetConfig(string key, GitConfigSource configSource, ITask SetConfig(string key, string value, GitConfigSource configSource, IOutputProcessor processor = null); - ITask GetConfigUserAndEmail(); + ITask GetConfigUserAndEmail(); ITask> ListLocks(bool local, BaseOutputListProcessor processor = null); @@ -255,26 +255,28 @@ public ITask SetConfig(string key, string value, GitConfigSource configS .Configure(processManager); } - public ITask GetConfigUserAndEmail() + public ITask GetConfigUserAndEmail() { string username = null; string email = null; - return GetConfig("user.name", GitConfigSource.User).Then((success, value) => { - if (success) - { - username = value; - } - - }).Then(GetConfig("user.email", GitConfigSource.User).Then((success, value) => { - if (success) - { - email = value; - } - })).Then(success => { - Logger.Trace("user.name:{1} user.email:{2}", success, username, email); - return new[] { username, email }; - }); + return GetConfig("user.name", GitConfigSource.User) + .Then((success, value) => { + if (success) + { + username = value; + } + }) + .Then(GetConfig("user.email", GitConfigSource.User) + .Then((success, value) => { + if (success) + { + email = value; + } + })).Then(success => { + Logger.Trace("{0}:{1} {2}:{3}", "user.name", username, "user.email", email); + return new User { Name= username, Email = email }; + }); } public ITask> ListLocks(bool local, BaseOutputListProcessor processor = null) diff --git a/src/GitHub.Api/Git/RepositoryManager.cs b/src/GitHub.Api/Git/RepositoryManager.cs index 5f82595a7..fa458c184 100644 --- a/src/GitHub.Api/Git/RepositoryManager.cs +++ b/src/GitHub.Api/Git/RepositoryManager.cs @@ -301,18 +301,9 @@ public ITask UnlockFile(string file, bool force) private void LoadGitUser() { GitClient.GetConfigUserAndEmail() - .Then((success, strings) => { - var username = strings[0]; - var email = strings[1]; - - var user = new User { - Name = username, - Email = email - }; - + .Then((success, user) => { Logger.Trace("OnGitUserLoaded: {0}", user); OnGitUserLoaded?.Invoke(user); - }).Start(); } diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/InitProjectView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/InitProjectView.cs index fa87e3454..9a195b510 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/InitProjectView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/InitProjectView.cs @@ -96,12 +96,9 @@ private void CheckForUser() Logger.Trace("Checking for user"); isBusy = true; - GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, strings) => { - var username = strings[0]; - var email = strings[1]; - + GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, user) => { isBusy = false; - isUserDataPresent = success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email); + isUserDataPresent = success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email); hasCompletedInitialCheck = true; Logger.Trace("User Present: {0}", isUserDataPresent); diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs index 3a984b488..50c142657 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs @@ -22,7 +22,6 @@ class UserSettingsView : Subview [SerializeField] private string gitEmail; [SerializeField] private string newGitName; [SerializeField] private string newGitEmail; - [SerializeField] private User cachedUser; public override void InitializeView(IView parent) { @@ -63,15 +62,11 @@ public override void OnGUI() { if (Repository != null) { - Repository.User.Name = newGitName; + Repository.User.Name = gitName = newGitName; } else { - if (cachedUser == null) - { - cachedUser = new User(); - } - cachedUser.Name = newGitName; + gitName = newGitName; } } }) @@ -83,11 +78,11 @@ public override void OnGUI() { if (Repository != null) { - Repository.User.Email = newGitEmail; + Repository.User.Email = gitEmail = newGitEmail; } else { - cachedUser.Email = newGitEmail; + gitEmail = newGitEmail; } userDataHasChanged = true; @@ -107,49 +102,53 @@ public override void OnGUI() EditorGUI.EndDisabledGroup(); } + public override void OnEnable() + { + base.OnEnable(); + userDataHasChanged = true; + } + private void MaybeUpdateData() { - if (Repository == null) + if (userDataHasChanged) { - if (!String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath)) + userDataHasChanged = false; + + if (Repository == null) { - if ((cachedUser == null || String.IsNullOrEmpty(cachedUser.Name)) && GitClient != null) - { - GitClient.GetConfigUserAndEmail().FinallyInUI((success, ex, strings) => { - var username = strings[0]; - var email = strings[1]; - - if (success && !String.IsNullOrEmpty(username) && !String.IsNullOrEmpty(email)) - { - cachedUser = new User { - Name = username, - Email = email - }; - - userDataHasChanged = true; - Redraw(); - } - }).Start(); - } + UpdateUserDataFromClient(); } - - if (userDataHasChanged) + else { - newGitName = gitName = cachedUser.Name; - newGitEmail = gitEmail = cachedUser.Email; - userDataHasChanged = false; + newGitName = gitName = Repository.User.Name; + newGitEmail = gitEmail = Repository.User.Email; } - return; } + } - userDataHasChanged = Repository.User.Name != gitName || Repository.User.Email != gitEmail; + private void UpdateUserDataFromClient() + { + if (String.IsNullOrEmpty(EntryPoint.Environment.GitExecutablePath)) + { + return; + } - if (!userDataHasChanged) + if (GitClient == null) + { return; + } + + Logger.Trace("Update user data from GitClient"); - userDataHasChanged = false; - newGitName = gitName = Repository.User.Name; - newGitEmail = gitEmail = Repository.User.Email; + GitClient.GetConfigUserAndEmail() + .ThenInUI((success, user) => { + if (success && !String.IsNullOrEmpty(user.Name) && !String.IsNullOrEmpty(user.Email)) + { + newGitName = gitName = user.Name; + newGitEmail = gitEmail = user.Email; + Redraw(); + } + }).Start(); } public override bool IsBusy