mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-30 22:01:10 +08:00
feature: mark deleted repository and auto remove it after scan default clone dir (#576)
This commit is contained in:
@@ -453,6 +453,13 @@ namespace SourceGit.ViewModels
|
||||
Save();
|
||||
}
|
||||
|
||||
public void AutoRemoveInvalidNode()
|
||||
{
|
||||
var changed = RemoveInvalidRepositoriesRecursive(RepositoryNodes);
|
||||
if (changed)
|
||||
Save();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
if (_isLoading)
|
||||
@@ -567,6 +574,27 @@ namespace SourceGit.ViewModels
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool RemoveInvalidRepositoriesRecursive(List<RepositoryNode> collection)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
for (int i = collection.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var node = collection[i];
|
||||
if (node.IsInvalid)
|
||||
{
|
||||
collection.RemoveAt(i);
|
||||
changed = true;
|
||||
}
|
||||
else if (!node.IsRepository)
|
||||
{
|
||||
changed |= RemoveInvalidRepositoriesRecursive(node.SubNodes);
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static Preference _instance = null;
|
||||
private static bool _isLoading = false;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
@@ -48,6 +49,12 @@ namespace SourceGit.ViewModels
|
||||
set => SetProperty(ref _isVisible, value);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsInvalid
|
||||
{
|
||||
get => _isRepository && !Directory.Exists(_id);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public int Depth
|
||||
{
|
||||
|
||||
@@ -56,12 +56,9 @@ namespace SourceGit.ViewModels
|
||||
var group = FindOrCreateGroupRecursive(Preference.Instance.RepositoryNodes, relative);
|
||||
Preference.Instance.FindOrAddNodeByRepositoryPath(f, group, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Should not happen.
|
||||
}
|
||||
}
|
||||
|
||||
Preference.Instance.AutoRemoveInvalidNode();
|
||||
Welcome.Instance.Refresh();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user