Skip to content

Commit

Permalink
feat(#618): Match .dockerignore entry * to all files and directories
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Oct 23, 2022
1 parent 08e7fa5 commit e6dbb63
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- 594 Add `IDockerContainer.GetLogs`
- 601 Add `ITestcontainersBuilder<TDockerContainer>.WithImagePullPolicy` (@BenasB)
- 616 Add `ITestcontainersBuilder<TDockerContainer>.WithMacAddress` (@seb1992)
- 618 Match `.dockerignore` entry `*` to all files and directories

### Changed

Expand Down
13 changes: 8 additions & 5 deletions src/Testcontainers/Images/IgnoreFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public IgnoreFile(IEnumerable<string> patterns, ILogger logger)
// Trim each line.
.Select(line => line.Trim())

// Remove empty line.
.Where(line => !string.IsNullOrEmpty(line))

// Remove comment.
.Where(line => !line.StartsWith("#", StringComparison.Ordinal))

// Exclude files and directories.
.Select(line => line.TrimEnd('/'))

Expand All @@ -42,11 +48,8 @@ public IgnoreFile(IEnumerable<string> patterns, ILogger logger)
return line.EndsWith(filesAndDirectories, StringComparison.InvariantCulture) ? line.Substring(0, line.Length - filesAndDirectories.Length) : line;
})

// Remove empty line.
.Where(line => !string.IsNullOrEmpty(line))

// Remove comment.
.Where(line => !line.StartsWith("#", StringComparison.Ordinal))
// Exclude all files and directories (https://github.com/testcontainers/testcontainers-dotnet/issues/618).
.Select(line => "*".Equals(line, StringComparison.OrdinalIgnoreCase) ? "**" : line)

// Check if the pattern contains an optional prefix ("!"), which negates the pattern.
.Aggregate(new List<KeyValuePair<string, bool>>(), (lines, line) =>
Expand Down
10 changes: 7 additions & 3 deletions tests/Testcontainers.Tests/Fixtures/Images/IgnoreFileFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ public IgnoreFileFixture()
{
var logger = TestcontainersSettings.Logger;
var ignoreFilesAndDirectories = new IgnoreFile(new[] { "bin/", "obj/*" }, logger);
var ignoreAllFilesAndDirectories = new IgnoreFile(new[] { "*", "!README*.md" }, logger);
var ignoreNonRecursiveFiles = new IgnoreFile(new[] { "*/temp*" }, logger);
var ignoreNonRecursiveNestedFiles = new IgnoreFile(new[] { "*/*/temp*" }, logger);
var ignoreRecursiveFiles = new IgnoreFile(new[] { "**/*.txt" }, logger);
var ignoreSingleCharacterFiles = new IgnoreFile(new[] { "temp?" }, logger);
var ignoreExceptionFiles = new IgnoreFile(new[] { "*.md", "!README*.md", "README-secret.md" }, logger);
this.Add(ignoreFilesAndDirectories, "bin/Debug/net6.0", false);
this.Add(ignoreFilesAndDirectories, "obj/Debug/net6.0", false);
this.Add(ignoreFilesAndDirectories, "Testcontainers.sln", true);
this.Add(ignoreFilesAndDirectories, "bin/Debug", false);
this.Add(ignoreFilesAndDirectories, "obj/Debug", false);
this.Add(ignoreFilesAndDirectories, "README.md", true);
this.Add(ignoreAllFilesAndDirectories, "bin/Debug", false);
this.Add(ignoreAllFilesAndDirectories, "obj/Debug", false);
this.Add(ignoreAllFilesAndDirectories, "README.md", true);
this.Add(ignoreNonRecursiveFiles, "lipsum/temp", false);
this.Add(ignoreNonRecursiveFiles, "lipsum/temp.txt", false);
this.Add(ignoreNonRecursiveFiles, "lipsum/lorem/temp", true);
Expand Down

0 comments on commit e6dbb63

Please sign in to comment.