fix: avoid crashing when try to close a repository that has been deleted on disk

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-11-07 10:30:06 +08:00
parent 2ed83c5e2c
commit 311244b9ad

View File

@@ -536,14 +536,17 @@ namespace SourceGit.ViewModels
}
}
try
if (Directory.Exists(GitDir))
{
using var stream = File.Create(Path.Combine(GitDir, "sourcegit.filters"));
JsonSerializer.Serialize(stream, _historyFilterCollection, JsonCodeGen.Default.HistoryFilterCollection);
}
catch
{
// Ignore
try
{
using var stream = File.Create(Path.Combine(GitDir, "sourcegit.filters"));
JsonSerializer.Serialize(stream, _historyFilterCollection, JsonCodeGen.Default.HistoryFilterCollection);
}
catch
{
// Ignore
}
}
if (_cancellationRefreshBranches is { IsCancellationRequested: false })
@@ -561,6 +564,7 @@ namespace SourceGit.ViewModels
_autoFetchTimer = null;
_settings = null;
_historyFilterCollection = null;
_historyFilterMode = Models.FilterMode.None;
_watcher?.Dispose();