Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/GitHub.Api/Git/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ ITask<string> Unlock(string file, bool force,
ITask<Version> Version(IOutputProcessor<Version> processor = null);

ITask<Version> LfsVersion(IOutputProcessor<Version> processor = null);

ITask<User> 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;
Expand Down Expand Up @@ -260,23 +264,30 @@ public ITask<User> 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<User> 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<List<GitLock>> ListLocks(bool local, BaseOutputListProcessor<GitLock> processor = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
{
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -122,6 +112,7 @@ private void MaybeUpdateData()
{
newGitName = gitName = Repository.User.Name;
newGitEmail = gitEmail = Repository.User.Email;
needsSaving = false;
}
}
}
Expand All @@ -146,6 +137,7 @@ private void UpdateUserDataFromClient()
{
newGitName = gitName = user.Name;
newGitEmail = gitEmail = user.Email;
needsSaving = false;
Redraw();
}
}).Start();
Expand Down