mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
optimize(Configure): remove duplicated methods to configure repository
This commit is contained in:
parent
2409148869
commit
789231fdc4
1 changed files with 6 additions and 47 deletions
|
@ -1,5 +1,3 @@
|
|||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
|
@ -33,8 +31,8 @@ namespace SourceGit.UI {
|
|||
public Configure(Git.Repository repo) {
|
||||
this.repo = repo;
|
||||
|
||||
UserName = GetConfig("user.name");
|
||||
UserEmail = GetConfig("user.email");
|
||||
UserName = repo.GetConfig("user.name");
|
||||
UserEmail = repo.GetConfig("user.email");
|
||||
CommitTemplate = repo.CommitTemplate;
|
||||
|
||||
InitializeComponent();
|
||||
|
@ -50,11 +48,11 @@ namespace SourceGit.UI {
|
|||
|
||||
#region EVENTS
|
||||
private void Save(object sender, RoutedEventArgs e) {
|
||||
var oldUser = GetConfig("user.name");
|
||||
if (oldUser != UserName) SetConfig("user.name", UserName);
|
||||
var oldUser = repo.GetConfig("user.name");
|
||||
if (oldUser != UserName) repo.SetConfig("user.name", UserName);
|
||||
|
||||
var oldEmail = GetConfig("user.email");
|
||||
if (oldEmail != UserEmail) SetConfig("user.email", UserEmail);
|
||||
var oldEmail = repo.GetConfig("user.email");
|
||||
if (oldEmail != UserEmail) repo.SetConfig("user.email", UserEmail);
|
||||
|
||||
if (CommitTemplate != repo.CommitTemplate) {
|
||||
repo.CommitTemplate = CommitTemplate;
|
||||
|
@ -68,44 +66,5 @@ namespace SourceGit.UI {
|
|||
PopupManager.Close();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CONFIGURE
|
||||
private string GetConfig(string key) {
|
||||
if (!App.IsGitConfigured) return "";
|
||||
|
||||
var startInfo = new ProcessStartInfo();
|
||||
startInfo.FileName = App.Preference.GitExecutable;
|
||||
startInfo.Arguments = $"config {key}";
|
||||
startInfo.WorkingDirectory = repo.Path;
|
||||
startInfo.UseShellExecute = false;
|
||||
startInfo.CreateNoWindow = true;
|
||||
startInfo.RedirectStandardOutput = true;
|
||||
startInfo.StandardOutputEncoding = Encoding.UTF8;
|
||||
|
||||
var proc = new Process() { StartInfo = startInfo };
|
||||
proc.Start();
|
||||
var output = proc.StandardOutput.ReadToEnd();
|
||||
proc.WaitForExit();
|
||||
proc.Close();
|
||||
|
||||
return output.Trim();
|
||||
}
|
||||
|
||||
private void SetConfig(string key, string val) {
|
||||
if (!App.IsGitConfigured) return;
|
||||
|
||||
var startInfo = new ProcessStartInfo();
|
||||
startInfo.FileName = App.Preference.GitExecutable;
|
||||
startInfo.Arguments = $"config {key} \"{val}\"";
|
||||
startInfo.WorkingDirectory = repo.Path;
|
||||
startInfo.UseShellExecute = false;
|
||||
startInfo.CreateNoWindow = true;
|
||||
|
||||
var proc = new Process() { StartInfo = startInfo };
|
||||
proc.Start();
|
||||
proc.WaitForExit();
|
||||
proc.Close();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue