mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -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;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
@ -33,8 +31,8 @@ namespace SourceGit.UI {
|
||||||
public Configure(Git.Repository repo) {
|
public Configure(Git.Repository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
|
||||||
UserName = GetConfig("user.name");
|
UserName = repo.GetConfig("user.name");
|
||||||
UserEmail = GetConfig("user.email");
|
UserEmail = repo.GetConfig("user.email");
|
||||||
CommitTemplate = repo.CommitTemplate;
|
CommitTemplate = repo.CommitTemplate;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
@ -50,11 +48,11 @@ namespace SourceGit.UI {
|
||||||
|
|
||||||
#region EVENTS
|
#region EVENTS
|
||||||
private void Save(object sender, RoutedEventArgs e) {
|
private void Save(object sender, RoutedEventArgs e) {
|
||||||
var oldUser = GetConfig("user.name");
|
var oldUser = repo.GetConfig("user.name");
|
||||||
if (oldUser != UserName) SetConfig("user.name", UserName);
|
if (oldUser != UserName) repo.SetConfig("user.name", UserName);
|
||||||
|
|
||||||
var oldEmail = GetConfig("user.email");
|
var oldEmail = repo.GetConfig("user.email");
|
||||||
if (oldEmail != UserEmail) SetConfig("user.email", UserEmail);
|
if (oldEmail != UserEmail) repo.SetConfig("user.email", UserEmail);
|
||||||
|
|
||||||
if (CommitTemplate != repo.CommitTemplate) {
|
if (CommitTemplate != repo.CommitTemplate) {
|
||||||
repo.CommitTemplate = CommitTemplate;
|
repo.CommitTemplate = CommitTemplate;
|
||||||
|
@ -68,44 +66,5 @@ namespace SourceGit.UI {
|
||||||
PopupManager.Close();
|
PopupManager.Close();
|
||||||
}
|
}
|
||||||
#endregion
|
#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