diff --git a/src/Commands/Config.cs b/src/Commands/Config.cs index 62340aa3..e1016f1e 100644 --- a/src/Commands/Config.cs +++ b/src/Commands/Config.cs @@ -14,7 +14,10 @@ namespace SourceGit.Commands public Dictionary ListAll() { - Args = "config -l"; + if (string.IsNullOrEmpty(WorkingDirectory)) + Args = "config --global -l"; + else + Args = "config -l"; var output = ReadToEnd(); var rs = new Dictionary(); diff --git a/src/ViewModels/RepositoryConfigure.cs b/src/ViewModels/RepositoryConfigure.cs index 1409dfa2..6472e733 100644 --- a/src/ViewModels/RepositoryConfigure.cs +++ b/src/ViewModels/RepositoryConfigure.cs @@ -52,7 +52,7 @@ namespace SourceGit.ViewModels UserEmail = email; if (_cached.TryGetValue("commit.gpgsign", out var gpgCommitSign)) GPGCommitSigningEnabled = gpgCommitSign == "true"; - if (_cached.TryGetValue("tag.gpgSign", out var gpgTagSign)) + if (_cached.TryGetValue("tag.gpgsign", out var gpgTagSign)) GPGTagSigningEnabled = gpgTagSign == "true"; if (_cached.TryGetValue("user.signingkey", out var signingKey)) GPGUserSigningKey = signingKey; @@ -67,7 +67,7 @@ namespace SourceGit.ViewModels SetIfChanged("user.name", UserName); SetIfChanged("user.email", UserEmail); SetIfChanged("commit.gpgsign", GPGCommitSigningEnabled ? "true" : "false"); - SetIfChanged("tag.gpgSign", GPGTagSigningEnabled ? "true" : "false"); + SetIfChanged("tag.gpgsign", GPGTagSigningEnabled ? "true" : "false"); SetIfChanged("user.signingkey", GPGUserSigningKey); SetIfChanged("http.proxy", HttpProxy); return null; diff --git a/src/Views/Preference.axaml.cs b/src/Views/Preference.axaml.cs index 2cb9dca4..5669c9ea 100644 --- a/src/Views/Preference.axaml.cs +++ b/src/Views/Preference.axaml.cs @@ -157,7 +157,7 @@ namespace SourceGit.Views CRLFMode = Models.CRLFMode.Supported.Find(x => x.Value == crlf); if (config.TryGetValue("commit.gpgsign", out var gpgCommitSign)) EnableGPGCommitSigning = (gpgCommitSign == "true"); - if (config.TryGetValue("tag.gpgSign", out var gpgTagSign)) + if (config.TryGetValue("tag.gpgsign", out var gpgTagSign)) EnableGPGTagSigning = (gpgTagSign == "true"); if (config.TryGetValue("gpg.format", out var gpgFormat)) GPGFormat = Models.GPGFormat.Supported.Find(x => x.Value == gpgFormat) ?? Models.GPGFormat.Supported[0]; @@ -181,34 +181,15 @@ namespace SourceGit.Views private void CloseWindow(object sender, RoutedEventArgs e) { - var cmd = new Commands.Config(null); - - var config = cmd.ListAll(); - var oldUser = config.TryGetValue("user.name", out var user) ? user : string.Empty; - var oldEmail = config.TryGetValue("user.email", out var email) ? email : string.Empty; - var oldGPGSignKey = config.TryGetValue("user.signingkey", out var signingKey) ? signingKey : string.Empty; - var oldCRLF = config.TryGetValue("core.autocrlf", out var crlf) ? crlf : string.Empty; - var oldGPGFormat = config.TryGetValue("gpg.format", out var gpgFormat) ? gpgFormat : "opengpg"; - var oldGPGCommitSignEnable = config.TryGetValue("commit.gpgsign", out var gpgCommitSign) ? gpgCommitSign : "false"; - var oldGPGTagSignEnable = config.TryGetValue("tag.gpgSign", out var gpgTagSign) ? gpgTagSign : "false"; - var oldGPGExec = config.TryGetValue("gpg.program", out var program) ? program : string.Empty; - - if (DefaultUser != oldUser) - cmd.Set("user.name", DefaultUser); - if (DefaultEmail != oldEmail) - cmd.Set("user.email", DefaultEmail); - if (GPGUserKey != oldGPGSignKey) - cmd.Set("user.signingkey", GPGUserKey); - if (CRLFMode != null && CRLFMode.Value != oldCRLF) - cmd.Set("core.autocrlf", CRLFMode.Value); - if (EnableGPGCommitSigning != (oldGPGCommitSignEnable == "true")) - cmd.Set("commit.gpgsign", EnableGPGCommitSigning ? "true" : "false"); - if (EnableGPGTagSigning != (oldGPGTagSignEnable == "true")) - cmd.Set("tag.gpgSign", EnableGPGTagSigning ? "true" : "false"); - if (GPGFormat.Value != oldGPGFormat) - cmd.Set("gpg.format", GPGFormat.Value); - if (GPGExecutableFile != oldGPGExec) - cmd.Set($"gpg.{GPGFormat.Value}.program", GPGExecutableFile); + var config = new Commands.Config(null).ListAll(); + SetIfChanged(config, "user.name", DefaultUser); + SetIfChanged(config, "user.email", DefaultEmail); + SetIfChanged(config, "user.signingkey", GPGUserKey); + SetIfChanged(config, "core.autocrlf", CRLFMode.Value); + SetIfChanged(config, "commit.gpgsign", EnableGPGCommitSigning ? "true" : "false"); + SetIfChanged(config, "tag.gpgsign", EnableGPGTagSigning ? "true" : "false"); + SetIfChanged(config, "gpg.format", GPGFormat.Value); + SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGFormat.Value != "ssh" ? GPGExecutableFile : null); Close(); } @@ -303,5 +284,17 @@ namespace SourceGit.Views ViewModels.Preference.Instance.ExternalMergeToolPath = selected[0].Path.LocalPath; } } + + private void SetIfChanged(Dictionary cached, string key, string value) + { + bool changed = false; + if (cached.TryGetValue(key, out var old)) + changed = old != value; + else if (!string.IsNullOrEmpty(value)) + changed = true; + + if (changed) + new Commands.Config(null).Set(key, value); + } } }