Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ignored paths used by binary tool #40777

Merged
merged 8 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/SourceBuild/content/eng/allowed-sb-binaries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# This file is used by the Binary Tool to remove binaries from the VMR
# If importing a file, include the relative path to the file

# Well known non-checked in infrastructure
.git/
ellahathaway marked this conversation as resolved.
Show resolved Hide resolved
.dotnet/
.packages/
prereqs/packages/

**/*.bmp
**/*.doc
**/*.docx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static class DetectBinaries

var matcher = new Matcher(StringComparison.Ordinal);
matcher.AddInclude("**/*");
matcher.AddExcludePatterns(await GetIgnoredPatternsAsync(targetDirectory));

IEnumerable<string> matchingFiles = matcher.GetResultsInFullPath(targetDirectory);

Expand All @@ -45,46 +44,6 @@ public static class DetectBinaries
return unmatchedBinaryFiles;
}

private static async Task<List<string>> GetIgnoredPatternsAsync(string targetDirectory)
{
string gitDirectory = Path.Combine(targetDirectory, ".git");
bool isGitRepo = Directory.Exists(gitDirectory);

try
{
if (!isGitRepo)
{
// Configure a fake git repo to use so that we can run git clean -ndx
await ExecuteProcessAsync("git", $"-C {targetDirectory} init -q");
}

await ExecuteProcessAsync("git", $"-C {targetDirectory} config --global safe.directory {targetDirectory}");

string output = await ExecuteProcessAsync("git", $"-C {targetDirectory} clean -ndx");

List<string> ignoredPaths = output.Split(Environment.NewLine)
.Select(line => GitCleanRegex.Match(line))
.Where(match => match.Success)
.Select(match => match.Groups[3].Value)
.ToList();

if (isGitRepo)
{
ignoredPaths.Add(".git");
}

return ignoredPaths;
}
finally
{
// Ensure .git directory is deleted if it wasn't originally a git repo
if (!isGitRepo && Directory.Exists(gitDirectory))
{
Directory.Delete(gitDirectory, true);
}
}
}

private static async Task<bool> IsBinaryAsync(string filePath)
{
// Using the GNU diff heuristic to determine if a file is binary or not.
Expand Down