Skip to content

Commit 676835d

Browse files
committed
enhance: do NOT modify global .gitconfig if value equals git default (#465)
1 parent 86c6254 commit 676835d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/Views/Preference.axaml.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
128128
protected override void OnClosing(WindowClosingEventArgs e)
129129
{
130130
var config = new Commands.Config(null).ListAll();
131-
SetIfChanged(config, "user.name", DefaultUser);
132-
SetIfChanged(config, "user.email", DefaultEmail);
133-
SetIfChanged(config, "user.signingkey", GPGUserKey);
134-
SetIfChanged(config, "core.autocrlf", CRLFMode != null ? CRLFMode.Value : null);
135-
SetIfChanged(config, "commit.gpgsign", EnableGPGCommitSigning ? "true" : "false");
136-
SetIfChanged(config, "tag.gpgsign", EnableGPGTagSigning ? "true" : "false");
137-
SetIfChanged(config, "gpg.format", GPGFormat.Value);
131+
SetIfChanged(config, "user.name", DefaultUser, "");
132+
SetIfChanged(config, "user.email", DefaultEmail, "");
133+
SetIfChanged(config, "user.signingkey", GPGUserKey, "");
134+
SetIfChanged(config, "core.autocrlf", CRLFMode != null ? CRLFMode.Value : null, null);
135+
SetIfChanged(config, "commit.gpgsign", EnableGPGCommitSigning ? "true" : "false", "false");
136+
SetIfChanged(config, "tag.gpgsign", EnableGPGTagSigning ? "true" : "false", "false");
137+
SetIfChanged(config, "gpg.format", GPGFormat.Value, "opengpg");
138138

139139
if (!GPGFormat.Value.Equals("ssh", StringComparison.Ordinal))
140-
SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile);
140+
SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGExecutableFile, "");
141141

142142
base.OnClosing(e);
143143
}
@@ -244,12 +244,12 @@ private async void SelectExternalMergeTool(object _1, RoutedEventArgs _2)
244244
}
245245
}
246246

247-
private void SetIfChanged(Dictionary<string, string> cached, string key, string value)
247+
private void SetIfChanged(Dictionary<string, string> cached, string key, string value, string defValue)
248248
{
249249
bool changed = false;
250250
if (cached.TryGetValue(key, out var old))
251251
changed = old != value;
252-
else if (!string.IsNullOrEmpty(value))
252+
else if (!string.IsNullOrEmpty(value) && value != defValue)
253253
changed = true;
254254

255255
if (changed)

0 commit comments

Comments
 (0)