From 5e02b08d48a3b84b86cbcee99ed08c196069f722 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Tue, 27 Aug 2024 10:42:56 +0800 Subject: [PATCH] fix: avoid crash when closing a repo which is deleted in file system --- src/ViewModels/Repository.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 2a395c4a..94ded994 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -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();