-
-
Notifications
You must be signed in to change notification settings - Fork 38
feat: support variables in include/exclude glob patterns #161
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
Merged
alirezanet
merged 5 commits into
master
from
copilot/add-variables-in-includes-glob-pattern
Mar 11, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
34fb99c
Initial plan
Copilot 41c2ec9
feat: support variables in include/exclude glob patterns
Copilot 6efed18
fix: correct integration test assertions and expand test coverage
Copilot fb03f67
test: add regression tests for old behavior in Issue113Tests
Copilot 75b5b35
Merge branch 'master' into copilot/add-variables-in-includes-glob-pat…
alirezanet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,285 @@ | ||
| using System.Runtime.CompilerServices; | ||
| using DotNet.Testcontainers.Containers; | ||
| using FluentAssertions; | ||
|
|
||
| namespace HuskyIntegrationTests; | ||
|
|
||
| public class Issue113Tests(ITestOutputHelper output) | ||
| { | ||
| [Fact] | ||
| public async Task ArgsVariable_InIncludePattern_ShouldMatchFilesUnderArgsDirectory() | ||
| { | ||
| // arrange | ||
| const string taskRunner = | ||
| """ | ||
| { | ||
| "tasks": [ | ||
| { | ||
| "name": "Echo", | ||
| "command": "echo", | ||
| "args": [ | ||
| "${staged}" | ||
| ], | ||
| "include": [ | ||
| "${args}/**/*.cs" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| """; | ||
| await using var c = await ArrangeContainer(taskRunner); | ||
|
|
||
| // act: run with --args src (the include pattern becomes src/**/*.cs which matches) | ||
| var result = await c.BashAsync(output, "dotnet husky run --args src"); | ||
|
|
||
| // assert | ||
| result.ExitCode.Should().Be(0); | ||
| result.Stdout.Should().Contain(DockerHelper.SuccessfullyExecuted); | ||
| result.Stdout.Should().NotContain(DockerHelper.Skipped); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ArgsVariable_InIncludePattern_ShouldSkip_WhenNoMatchedFiles() | ||
| { | ||
| // arrange | ||
| const string taskRunner = | ||
| """ | ||
| { | ||
| "tasks": [ | ||
| { | ||
| "name": "Echo", | ||
| "command": "echo", | ||
| "args": [ | ||
| "${staged}" | ||
| ], | ||
| "include": [ | ||
| "${args}/**/*.cs" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| """; | ||
| await using var c = await ArrangeContainer(taskRunner); | ||
|
|
||
| // act: run with --args tests (the include pattern becomes tests/**/*.cs which does NOT match) | ||
| var result = await c.BashAsync(output, "dotnet husky run --args tests"); | ||
|
|
||
| // assert | ||
| result.ExitCode.Should().Be(0); | ||
| result.Stdout.Should().Contain(DockerHelper.Skipped); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ArgsVariable_InExcludePattern_ShouldSkip_WhenExcludedByArgs() | ||
| { | ||
| // arrange | ||
| const string taskRunner = | ||
| """ | ||
| { | ||
| "tasks": [ | ||
| { | ||
| "name": "Echo", | ||
| "command": "echo", | ||
| "args": [ | ||
| "${staged}" | ||
| ], | ||
| "include": [ | ||
| "**/*.cs" | ||
| ], | ||
| "exclude": [ | ||
| "${args}/**/*.cs" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| """; | ||
| await using var c = await ArrangeContainer(taskRunner); | ||
|
|
||
| // act: run with --args src (the exclude pattern becomes src/**/*.cs which excludes src/Foo.cs) | ||
| var result = await c.BashAsync(output, "dotnet husky run --args src"); | ||
|
|
||
| // assert | ||
| result.ExitCode.Should().Be(0); | ||
| result.Stdout.Should().Contain(DockerHelper.Skipped); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task ArgsVariable_InExcludePattern_ShouldNotSkip_WhenNotExcludedByArgs() | ||
| { | ||
| // arrange | ||
| const string taskRunner = | ||
| """ | ||
| { | ||
| "tasks": [ | ||
| { | ||
| "name": "Echo", | ||
| "command": "echo", | ||
| "args": [ | ||
| "${staged}" | ||
| ], | ||
| "include": [ | ||
| "**/*.cs" | ||
| ], | ||
| "exclude": [ | ||
| "${args}/**/*.cs" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| """; | ||
| await using var c = await ArrangeContainer(taskRunner); | ||
|
|
||
| // act: run with --args tests (the exclude pattern becomes tests/**/*.cs which does NOT exclude src/Foo.cs) | ||
| var result = await c.BashAsync(output, "dotnet husky run --args tests"); | ||
|
|
||
| // assert | ||
| result.ExitCode.Should().Be(0); | ||
| result.Stdout.Should().Contain(DockerHelper.SuccessfullyExecuted); | ||
| result.Stdout.Should().NotContain(DockerHelper.Skipped); | ||
| } | ||
|
|
||
| // ── Regression tests: old behavior must still work ────────────────────────── | ||
|
|
||
| [Fact] | ||
| public async Task StagedVariable_WithStaticInclude_ShouldRun_WhenPatternMatchesStagedFiles() | ||
| { | ||
| // arrange: old behavior — ${staged} in args, plain static include glob (no ${args}) | ||
| const string taskRunner = | ||
| """ | ||
| { | ||
| "tasks": [ | ||
| { | ||
| "name": "Echo", | ||
| "command": "echo", | ||
| "filteringRule": "staged", | ||
| "args": [ | ||
| "${staged}" | ||
| ], | ||
| "include": [ | ||
| "**/*.cs" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| """; | ||
| await using var c = await ArrangeContainer(taskRunner); | ||
|
|
||
| // act: run without --args; staged src/Foo.cs matches **/*.cs | ||
| var result = await c.BashAsync(output, "dotnet husky run"); | ||
|
|
||
| // assert | ||
| result.ExitCode.Should().Be(0); | ||
| result.Stdout.Should().Contain(DockerHelper.SuccessfullyExecuted); | ||
| result.Stdout.Should().NotContain(DockerHelper.Skipped); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task StagedVariable_WithStaticInclude_ShouldSkip_WhenPatternDoesNotMatchStagedFiles() | ||
| { | ||
| // arrange: old behavior — ${staged} in args, plain static include glob (no ${args}) | ||
| const string taskRunner = | ||
| """ | ||
| { | ||
| "tasks": [ | ||
| { | ||
| "name": "Echo", | ||
| "command": "echo", | ||
| "filteringRule": "staged", | ||
| "args": [ | ||
| "${staged}" | ||
| ], | ||
| "include": [ | ||
| "**/*.ts" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| """; | ||
| await using var c = await ArrangeContainer(taskRunner); | ||
|
|
||
| // act: run without --args; no .ts files are staged so no match | ||
| var result = await c.BashAsync(output, "dotnet husky run"); | ||
|
|
||
| // assert | ||
| result.ExitCode.Should().Be(0); | ||
| result.Stdout.Should().Contain(DockerHelper.Skipped); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task NoVariable_WithStaticArgs_WithMatchingInclude_ShouldRun() | ||
| { | ||
| // arrange: old behavior — no variables anywhere, plain static args and include | ||
| const string taskRunner = | ||
| """ | ||
| { | ||
| "tasks": [ | ||
| { | ||
| "name": "Echo", | ||
| "command": "echo", | ||
| "filteringRule": "staged", | ||
| "args": [ | ||
| "Husky.Net is awesome!" | ||
| ], | ||
| "include": [ | ||
| "**/*.cs" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| """; | ||
| await using var c = await ArrangeContainer(taskRunner); | ||
|
|
||
| // act: run without --args; staged src/Foo.cs matches **/*.cs | ||
| var result = await c.BashAsync(output, "dotnet husky run"); | ||
|
|
||
| // assert | ||
| result.ExitCode.Should().Be(0); | ||
| result.Stdout.Should().Contain(DockerHelper.SuccessfullyExecuted); | ||
| result.Stdout.Should().NotContain(DockerHelper.Skipped); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task StaticIncludePattern_ShouldNotBeAffectedByArgs_WhenNoArgsVariable() | ||
| { | ||
| // arrange: new behavior baseline — static include pattern (no ${args}), | ||
| // verify pattern is NOT substituted even when --args is supplied | ||
| const string taskRunner = | ||
| """ | ||
| { | ||
| "tasks": [ | ||
| { | ||
| "name": "Echo", | ||
| "command": "echo", | ||
| "filteringRule": "staged", | ||
| "args": [ | ||
| "${staged}" | ||
| ], | ||
| "include": [ | ||
| "**/*.cs" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| """; | ||
| await using var c = await ArrangeContainer(taskRunner); | ||
|
|
||
| // act: --args is provided but the include pattern has no ${args}, so it | ||
| // must remain a plain **/*.cs glob and still match staged src/Foo.cs | ||
| var result = await c.BashAsync(output, "dotnet husky run --args tests"); | ||
|
|
||
| // assert | ||
| result.ExitCode.Should().Be(0); | ||
| result.Stdout.Should().Contain(DockerHelper.SuccessfullyExecuted); | ||
| result.Stdout.Should().NotContain(DockerHelper.Skipped); | ||
| } | ||
|
|
||
| private async Task<IContainer> ArrangeContainer(string taskRunner, [CallerMemberName] string name = null!) | ||
| { | ||
| var c = await DockerHelper.StartWithInstalledHusky(name); | ||
| await c.UpdateTaskRunner(taskRunner); | ||
| await c.BashAsync("mkdir -p /test/src"); | ||
| await c.BashAsync("echo 'public class Foo {}' > /test/src/Foo.cs"); | ||
| await c.BashAsync("git add ."); | ||
| return c; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this check mean we only support
${args}variable? if not, we should support all possible variables as beforeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently only
${args}is supported in include/exclude glob patterns. Other variables like${staged},${all-files},${last-commit}, and${git-files}expand to file path lists, not string fragments — embedding file paths as glob patterns doesn't make semantic sense.${args}is the only variable that provides literal string values (e.g., a directory name) suitable for substitution into a glob pattern like${args}/**/*.cs.