fix: avoid crash when closing a repo which is deleted in file system

This commit is contained in:
Gadfly 2024-08-27 10:42:56 +08:00
parent 80559ce199
commit 5e02b08d48
No known key found for this signature in database

View file

@ -356,7 +356,14 @@ namespace SourceGit.ViewModels
SelectedView = null; // Do NOT modify. Used to remove exists widgets for GC.Collect
var settingsSerialized = JsonSerializer.Serialize(_settings, JsonCodeGen.Default.RepositorySettings);
File.WriteAllText(Path.Combine(_gitDir, "sourcegit.settings"), settingsSerialized);
try
{
File.WriteAllText(Path.Combine(_gitDir, "sourcegit.settings"), settingsSerialized);
}
catch (DirectoryNotFoundException)
{
// Ignore
}
_settings = null;
_watcher?.Dispose();