Skip to content

Commit 311244b

Browse files
committed
fix: avoid crashing when try to close a repository that has been deleted on disk
Signed-off-by: leo <longshuang@msn.cn>
1 parent 2ed83c5 commit 311244b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/ViewModels/Repository.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,17 @@ public void Close()
536536
}
537537
}
538538

539-
try
540-
{
541-
using var stream = File.Create(Path.Combine(GitDir, "sourcegit.filters"));
542-
JsonSerializer.Serialize(stream, _historyFilterCollection, JsonCodeGen.Default.HistoryFilterCollection);
543-
}
544-
catch
539+
if (Directory.Exists(GitDir))
545540
{
546-
// Ignore
541+
try
542+
{
543+
using var stream = File.Create(Path.Combine(GitDir, "sourcegit.filters"));
544+
JsonSerializer.Serialize(stream, _historyFilterCollection, JsonCodeGen.Default.HistoryFilterCollection);
545+
}
546+
catch
547+
{
548+
// Ignore
549+
}
547550
}
548551

549552
if (_cancellationRefreshBranches is { IsCancellationRequested: false })
@@ -561,6 +564,7 @@ public void Close()
561564
_autoFetchTimer = null;
562565

563566
_settings = null;
567+
_historyFilterCollection = null;
564568
_historyFilterMode = Models.FilterMode.None;
565569

566570
_watcher?.Dispose();

0 commit comments

Comments
 (0)