diff --git a/src/GitHub.Api/Git/GitClient.cs b/src/GitHub.Api/Git/GitClient.cs index 9acef5286..a9f5c7e4c 100644 --- a/src/GitHub.Api/Git/GitClient.cs +++ b/src/GitHub.Api/Git/GitClient.cs @@ -83,10 +83,14 @@ ITask Unlock(string file, bool force, ITask Version(IOutputProcessor processor = null); ITask LfsVersion(IOutputProcessor processor = null); + + ITask SetConfigUserAndEmail(string username, string email); } class GitClient : IGitClient { + private const string UserNameConfigKey = "user.name"; + private const string UserEmailConfigKey = "user.email"; private readonly IEnvironment environment; private readonly IProcessManager processManager; private readonly ITaskManager taskManager; @@ -260,23 +264,30 @@ public ITask GetConfigUserAndEmail() string username = null; string email = null; - return GetConfig("user.name", GitConfigSource.User) + return GetConfig(UserNameConfigKey, GitConfigSource.User) .Then((success, value) => { if (success) { username = value; } }) - .Then(GetConfig("user.email", GitConfigSource.User) + .Then(GetConfig(UserEmailConfigKey, 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 }; - }); + Logger.Trace("{0}:{1} {2}:{3}", UserNameConfigKey, username, UserEmailConfigKey, email); + return new User { Name = username, Email = email }; + }); + } + + public ITask SetConfigUserAndEmail(string username, string email) + { + return SetConfig(UserNameConfigKey, username, GitConfigSource.User) + .Then(SetConfig(UserEmailConfigKey, email, GitConfigSource.User)) + .Then(b => new User { Name = username, Email = email }); } public ITask> ListLocks(bool local, BaseOutputListProcessor processor = null) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs index 50c142657..6bf1945a0 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/UserSettingsView.cs @@ -22,6 +22,7 @@ class UserSettingsView : Subview [SerializeField] private string gitEmail; [SerializeField] private string newGitName; [SerializeField] private string newGitEmail; + [SerializeField] private bool needsSaving; public override void InitializeView(IView parent) { @@ -42,11 +43,17 @@ public override void OnGUI() EditorGUI.BeginDisabledGroup(IsBusy || Parent.IsBusy); { - newGitName = EditorGUILayout.TextField(GitConfigNameLabel, newGitName); - newGitEmail = EditorGUILayout.TextField(GitConfigEmailLabel, newGitEmail); + EditorGUI.BeginChangeCheck(); + { + newGitName = EditorGUILayout.TextField(GitConfigNameLabel, newGitName); + newGitEmail = EditorGUILayout.TextField(GitConfigEmailLabel, newGitEmail); + } - var needsSaving = (newGitName != gitName || newGitEmail != gitEmail) - && !(string.IsNullOrEmpty(newGitName) || string.IsNullOrEmpty(newGitEmail)); + if (EditorGUI.EndChangeCheck()) + { + needsSaving = !(string.IsNullOrEmpty(newGitName) || string.IsNullOrEmpty(newGitEmail)) + && (newGitName != gitName || newGitEmail != gitEmail); + } EditorGUI.BeginDisabledGroup(!needsSaving); { @@ -55,45 +62,28 @@ public override void OnGUI() GUI.FocusControl(null); isBusy = true; - GitClient.SetConfig("user.name", newGitName, GitConfigSource.User) - .Then((success, value) => - { + GitClient.SetConfigUserAndEmail(newGitName, newGitEmail) + .FinallyInUI((success, exception, user) => { + isBusy = false; if (success) { if (Repository != null) { Repository.User.Name = gitName = newGitName; + Repository.User.Email = gitEmail = newGitEmail; } else { gitName = newGitName; + gitEmail = newGitEmail; } + + needsSaving = false; + + Redraw(); + Finish(true); } }) - .Then( - GitClient.SetConfig("user.email", newGitEmail, GitConfigSource.User) - .Then((success, value) => - { - if (success) - { - if (Repository != null) - { - Repository.User.Email = gitEmail = newGitEmail; - } - else - { - gitEmail = newGitEmail; - } - - userDataHasChanged = true; - } - })) - .FinallyInUI((_, __) => - { - isBusy = false; - Redraw(); - Finish(true); - }) .Start(); } } @@ -122,6 +112,7 @@ private void MaybeUpdateData() { newGitName = gitName = Repository.User.Name; newGitEmail = gitEmail = Repository.User.Email; + needsSaving = false; } } } @@ -146,6 +137,7 @@ private void UpdateUserDataFromClient() { newGitName = gitName = user.Name; newGitEmail = gitEmail = user.Email; + needsSaving = false; Redraw(); } }).Start();