fix: remove trailing slash in paths, to avoid failing comparisons.

This is needed since DirectoryInfo.Fullname (and .FullPath) will not "normalize" trailing slashes, so direct equality tests are error-prone.
This fixes a bug in ScanRepositories.GetUnmanagedRepositories(), where not all Git repo folders were added.
(Also, corrected a variable name from 'founded' to 'found'.)
This commit is contained in:
Göran W 2025-06-03 13:34:52 +02:00 committed by leo
parent 75c32c1a01
commit 54c05ac35a
No known key found for this signature in database

View file

@ -31,8 +31,8 @@ namespace SourceGit.ViewModels
watch.Start();
var rootDir = new DirectoryInfo(RootDir);
var founded = new List<FoundRepository>();
GetUnmanagedRepositories(rootDir, founded, new EnumerationOptions()
var found = new List<FoundRepository>();
GetUnmanagedRepositories(rootDir, found, new EnumerationOptions()
{
AttributesToSkip = FileAttributes.Hidden | FileAttributes.System,
IgnoreInaccessible = true,
@ -46,11 +46,11 @@ namespace SourceGit.ViewModels
Dispatcher.UIThread.Invoke(() =>
{
var normalizedRoot = rootDir.FullName.Replace("\\", "/");
var normalizedRoot = rootDir.FullName.Replace("\\", "/").TrimEnd('/');
foreach (var f in founded)
foreach (var f in found)
{
var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace("\\", "/");
var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace("\\", "/").TrimEnd('/');
if (parent.Equals(normalizedRoot, StringComparison.Ordinal))
{
Preferences.Instance.FindOrAddNodeByRepositoryPath(f.Path, null, false);
@ -93,7 +93,7 @@ namespace SourceGit.ViewModels
CallUIThread(() => ProgressDescription = $"Scanning {subdir.FullName}...");
var normalizedSelf = subdir.FullName.Replace("\\", "/");
var normalizedSelf = subdir.FullName.Replace("\\", "/").TrimEnd('/');
if (_managed.Contains(normalizedSelf))
continue;
@ -103,7 +103,7 @@ namespace SourceGit.ViewModels
var test = new Commands.QueryRepositoryRootPath(subdir.FullName).ReadToEnd();
if (test.IsSuccess && !string.IsNullOrEmpty(test.StdOut))
{
var normalized = test.StdOut.Trim().Replace("\\", "/");
var normalized = test.StdOut.Trim().Replace("\\", "/").TrimEnd('/');
if (!_managed.Contains(normalized))
outs.Add(new FoundRepository(normalized, false));
}