fix: tag.gpgsign setting not updated

This commit is contained in:
leo 2024-06-19 10:21:36 +08:00
parent 9ae6df4597
commit 86226d5484
No known key found for this signature in database
3 changed files with 28 additions and 32 deletions

View file

@ -14,7 +14,10 @@ namespace SourceGit.Commands
public Dictionary<string, string> ListAll() public Dictionary<string, string> ListAll()
{ {
Args = "config -l"; if (string.IsNullOrEmpty(WorkingDirectory))
Args = "config --global -l";
else
Args = "config -l";
var output = ReadToEnd(); var output = ReadToEnd();
var rs = new Dictionary<string, string>(); var rs = new Dictionary<string, string>();

View file

@ -52,7 +52,7 @@ namespace SourceGit.ViewModels
UserEmail = email; UserEmail = email;
if (_cached.TryGetValue("commit.gpgsign", out var gpgCommitSign)) if (_cached.TryGetValue("commit.gpgsign", out var gpgCommitSign))
GPGCommitSigningEnabled = gpgCommitSign == "true"; GPGCommitSigningEnabled = gpgCommitSign == "true";
if (_cached.TryGetValue("tag.gpgSign", out var gpgTagSign)) if (_cached.TryGetValue("tag.gpgsign", out var gpgTagSign))
GPGTagSigningEnabled = gpgTagSign == "true"; GPGTagSigningEnabled = gpgTagSign == "true";
if (_cached.TryGetValue("user.signingkey", out var signingKey)) if (_cached.TryGetValue("user.signingkey", out var signingKey))
GPGUserSigningKey = signingKey; GPGUserSigningKey = signingKey;
@ -67,7 +67,7 @@ namespace SourceGit.ViewModels
SetIfChanged("user.name", UserName); SetIfChanged("user.name", UserName);
SetIfChanged("user.email", UserEmail); SetIfChanged("user.email", UserEmail);
SetIfChanged("commit.gpgsign", GPGCommitSigningEnabled ? "true" : "false"); SetIfChanged("commit.gpgsign", GPGCommitSigningEnabled ? "true" : "false");
SetIfChanged("tag.gpgSign", GPGTagSigningEnabled ? "true" : "false"); SetIfChanged("tag.gpgsign", GPGTagSigningEnabled ? "true" : "false");
SetIfChanged("user.signingkey", GPGUserSigningKey); SetIfChanged("user.signingkey", GPGUserSigningKey);
SetIfChanged("http.proxy", HttpProxy); SetIfChanged("http.proxy", HttpProxy);
return null; return null;

View file

@ -157,7 +157,7 @@ namespace SourceGit.Views
CRLFMode = Models.CRLFMode.Supported.Find(x => x.Value == crlf); CRLFMode = Models.CRLFMode.Supported.Find(x => x.Value == crlf);
if (config.TryGetValue("commit.gpgsign", out var gpgCommitSign)) if (config.TryGetValue("commit.gpgsign", out var gpgCommitSign))
EnableGPGCommitSigning = (gpgCommitSign == "true"); EnableGPGCommitSigning = (gpgCommitSign == "true");
if (config.TryGetValue("tag.gpgSign", out var gpgTagSign)) if (config.TryGetValue("tag.gpgsign", out var gpgTagSign))
EnableGPGTagSigning = (gpgTagSign == "true"); EnableGPGTagSigning = (gpgTagSign == "true");
if (config.TryGetValue("gpg.format", out var gpgFormat)) if (config.TryGetValue("gpg.format", out var gpgFormat))
GPGFormat = Models.GPGFormat.Supported.Find(x => x.Value == gpgFormat) ?? Models.GPGFormat.Supported[0]; 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) private void CloseWindow(object sender, RoutedEventArgs e)
{ {
var cmd = new Commands.Config(null); var config = new Commands.Config(null).ListAll();
SetIfChanged(config, "user.name", DefaultUser);
var config = cmd.ListAll(); SetIfChanged(config, "user.email", DefaultEmail);
var oldUser = config.TryGetValue("user.name", out var user) ? user : string.Empty; SetIfChanged(config, "user.signingkey", GPGUserKey);
var oldEmail = config.TryGetValue("user.email", out var email) ? email : string.Empty; SetIfChanged(config, "core.autocrlf", CRLFMode.Value);
var oldGPGSignKey = config.TryGetValue("user.signingkey", out var signingKey) ? signingKey : string.Empty; SetIfChanged(config, "commit.gpgsign", EnableGPGCommitSigning ? "true" : "false");
var oldCRLF = config.TryGetValue("core.autocrlf", out var crlf) ? crlf : string.Empty; SetIfChanged(config, "tag.gpgsign", EnableGPGTagSigning ? "true" : "false");
var oldGPGFormat = config.TryGetValue("gpg.format", out var gpgFormat) ? gpgFormat : "opengpg"; SetIfChanged(config, "gpg.format", GPGFormat.Value);
var oldGPGCommitSignEnable = config.TryGetValue("commit.gpgsign", out var gpgCommitSign) ? gpgCommitSign : "false"; SetIfChanged(config, $"gpg.{GPGFormat.Value}.program", GPGFormat.Value != "ssh" ? GPGExecutableFile : null);
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);
Close(); Close();
} }
@ -303,5 +284,17 @@ namespace SourceGit.Views
ViewModels.Preference.Instance.ExternalMergeToolPath = selected[0].Path.LocalPath; ViewModels.Preference.Instance.ExternalMergeToolPath = selected[0].Path.LocalPath;
} }
} }
private void SetIfChanged(Dictionary<string, string> 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);
}
} }
} }