From 3957f4308fa191e16954e7b8fd2e5f0265223065 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Mon, 26 Aug 2019 10:01:24 -0400 Subject: [PATCH] SparseTests: update prefix check to match cone mode Signed-off-by: Derrick Stolee --- .../Should/FileSystemShouldExtensions.cs | 11 +++++++---- .../Tests/GitCommands/GitRepoTests.cs | 11 +---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Scalar.FunctionalTests/Should/FileSystemShouldExtensions.cs b/Scalar.FunctionalTests/Should/FileSystemShouldExtensions.cs index b2ae343141..4613751097 100644 --- a/Scalar.FunctionalTests/Should/FileSystemShouldExtensions.cs +++ b/Scalar.FunctionalTests/Should/FileSystemShouldExtensions.cs @@ -257,6 +257,9 @@ private static bool IsMatchedPath(FileSystemInfo info, string repoRoot, string[] } string localPath = info.FullName.Substring(repoRoot.Length + 1); + int parentLength = info.FullName.LastIndexOf(System.IO.Path.DirectorySeparatorChar); + + string parentPath = parentLength > 0 ? info.FullName.Substring(0, parentLength + 1) : null; if (localPath.Equals(".git", StringComparison.OrdinalIgnoreCase)) { @@ -274,15 +277,15 @@ private static bool IsMatchedPath(FileSystemInfo info, string repoRoot, string[] foreach (string prefixDir in prefixes) { - if (localPath.StartsWith(prefixDir, StringComparison.OrdinalIgnoreCase)) + if (localPath.Equals(prefixDir, StringComparison.OrdinalIgnoreCase) || + localPath.StartsWith(prefixDir + System.IO.Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) { return true; } - if (prefixDir.StartsWith(localPath, StringComparison.OrdinalIgnoreCase) && - Directory.Exists(info.FullName)) + if (parentPath != null && prefixDir.StartsWith(parentPath, StringComparison.OrdinalIgnoreCase)) { - // For example: localPath = "Scalar" and prefix is "Scalar\\Scalar". + // For example: localPath = "Scalar\\file.txt", parentPath="Scalar\\" and prefix is "Scalar\\Scalar". return true; } } diff --git a/Scalar.FunctionalTests/Tests/GitCommands/GitRepoTests.cs b/Scalar.FunctionalTests/Tests/GitCommands/GitRepoTests.cs index 465a109b88..da2a56283c 100644 --- a/Scalar.FunctionalTests/Tests/GitCommands/GitRepoTests.cs +++ b/Scalar.FunctionalTests/Tests/GitCommands/GitRepoTests.cs @@ -4,10 +4,8 @@ using Scalar.FunctionalTests.Should; using Scalar.FunctionalTests.Tools; using Scalar.Tests.Should; -using System; using System.IO; using System.Linq; -using System.Text; namespace Scalar.FunctionalTests.Tests.GitCommands { @@ -133,20 +131,13 @@ public virtual void SetupForTest() if (this.validateWorkingTree == Settings.ValidateWorkingTreeMode.SparseMode) { - StringBuilder input = new StringBuilder(capacity: SparseModeFolders.Sum(s => s.Length + 1)); - - foreach (string s in SparseModeFolders) - { - input.Append($"{s}\n"); - } - ScalarProcess scalar = new ScalarProcess(this.Enlistment); string replacedInput = input.ToString().Replace(Path.DirectorySeparatorChar, '/'); scalar.Prefetch("--stdin-folders-list", failOnError: true, standardInput: input.ToString()); this.RunGitCommand("sparse-checkout add", standardInput: replacedInput); // The WithDeepStructure method requires trailing directory separators - this.pathPrefixes = SparseModeFolders.Select(x => x + Path.DirectorySeparatorChar).ToArray(); + this.pathPrefixes = SparseModeFolders; } this.ValidateGitCommand("checkout " + this.ControlGitRepo.Commitish);