Skip to content

Commit

Permalink
SparseTests: update prefix check to match cone mode
Browse files Browse the repository at this point in the history
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
derrickstolee committed Aug 27, 2019
1 parent 4b4756c commit 3957f43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
11 changes: 7 additions & 4 deletions Scalar.FunctionalTests/Should/FileSystemShouldExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand All @@ -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;
}
}
Expand Down
11 changes: 1 addition & 10 deletions Scalar.FunctionalTests/Tests/GitCommands/GitRepoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3957f43

Please sign in to comment.