From eaf3ef3f96c7babd1131788d14b145a5050de2fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20W?= Date: Tue, 3 Jun 2025 13:34:52 +0200 Subject: [PATCH] Bug-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'.) --- src/ViewModels/ScanRepositories.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ViewModels/ScanRepositories.cs b/src/ViewModels/ScanRepositories.cs index cec932eb..743fcf27 100644 --- a/src/ViewModels/ScanRepositories.cs +++ b/src/ViewModels/ScanRepositories.cs @@ -31,8 +31,8 @@ namespace SourceGit.ViewModels watch.Start(); var rootDir = new DirectoryInfo(RootDir); - var founded = new List(); - GetUnmanagedRepositories(rootDir, founded, new EnumerationOptions() + var found = new List(); + 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)); }