style<Repository>: normalize repository's path

This commit is contained in:
leo 2024-03-01 13:40:12 +08:00
parent 1c005983c7
commit e3a7abe776
7 changed files with 26 additions and 19 deletions

View file

@ -209,23 +209,22 @@ namespace SourceGit.ViewModels {
}
public static Repository FindRepository(string path) {
var dir = new DirectoryInfo(path);
foreach (var repo in _instance.Repositories) {
if (repo.FullPath == dir.FullName) return repo;
if (repo.FullPath == path) return repo;
}
return null;
}
public static Repository AddRepository(string rootDir, string gitDir) {
var repo = FindRepository(rootDir);
var normalized = rootDir.Replace('\\', '/');
var repo = FindRepository(normalized);
if (repo != null) {
repo.GitDir = gitDir;
return repo;
}
var dir = new DirectoryInfo(rootDir);
repo = new Repository() {
FullPath = dir.FullName,
FullPath = normalized,
GitDir = gitDir
};