From 676835dee56d0c802971ced4e7598ea592b14df1 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 12 Sep 2024 10:33:52 +0800 Subject: [PATCH] enhance: do NOT modify global .gitconfig if value equals git default (#465) --- src/Views/Preference.axaml.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Views/Preference.axaml.cs b/src/Views/Preference.axaml.cs index 25dbfd96..141c1baf 100644 --- a/src/Views/Preference.axaml.cs +++ b/src/Views/Preference.axaml.cs @@ -128,16 +128,16 @@ namespace SourceGit.Views protected override void OnClosing(WindowClosingEventArgs e) { 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 != null ? CRLFMode.Value : null); - SetIfChanged(config, "commit.gpgsign", EnableGPGCommitSigning ? "true" : "false"); - SetIfChanged(config, "tag.gpgsign", EnableGPGTagSigning ? "true" : "false"); - SetIfChanged(config, "gpg.format", GPGFormat.Value); + SetIfChanged(config, "user.name", DefaultUser, ""); + SetIfChanged(config, "user.email", DefaultEmail, ""); + SetIfChanged(config, "user.signingkey", GPGUserKey, ""); + SetIfChanged(config, "core.autocrlf", CRLFMode != null ? CRLFMode.Value : null, null); + SetIfChanged(config, "commit.gpgsign", EnableGPGCommitSigning ? "true" : "false", "false"); + SetIfChanged(config, "tag.gpgsign", EnableGPGTagSigning ? "true" : "false", "false"); + SetIfChanged(config, "gpg.format", GPGFormat.Value, "opengpg"); if (!GPGFormat.Value.Equals("ssh", StringComparison.Ordinal)) - SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile); + SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile, ""); base.OnClosing(e); } @@ -244,12 +244,12 @@ namespace SourceGit.Views } } - private void SetIfChanged(Dictionary cached, string key, string value) + private void SetIfChanged(Dictionary cached, string key, string value, string defValue) { bool changed = false; if (cached.TryGetValue(key, out var old)) changed = old != value; - else if (!string.IsNullOrEmpty(value)) + else if (!string.IsNullOrEmpty(value) && value != defValue) changed = true; if (changed)