You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by ThijmenDam May 21, 2024
Hi @alirezanet and contributors, first of all I'd like to thank you for this very useful package.
So, our team would greatly benefit from the possibility of using variables in the "include" glob pattern. For example:
{
"tasks": [
{
"name": "dotnet-format-staged-files",
"group": "pre-commit-operations",
"command": "dotnet",
"args": [
"format",
"${args}",
"--verbosity",
"diagnostic",
"--no-restore",
"--include",
"${staged}"
],
"include": [
"${args}/**/*.cs"<---- this is what I refer to
]
}
]
}
The reason this would be very useful for our team is performance. To elaborate, some of our repositories contain multiple solutions, and without variables in the "include" glob pattern, we are not able to execute dotnet formatonly for the solutions that contain staged files. This means that dotnet format is executed for every solution, even if there are no staged files from that solution (which slows down the pre-commit hook by a lot).
To illustrate, consider the following pre-commit hook:
echo"[PRE-COMMIT] Formatting staged .NET files..."
repository_root=$(dirname "$(dirname "$(dirname "$0")")")# Loop through all subdirectories of the root folder of the repositoryfordirin"$repository_root"/*;do# Ignore the directory if it is not a folder
[ !-d"$dir" ] &&continue# Ignore directories that are not a .NET solution folder
[ -z"$(find "$dir" -type f -name '*.sln')" ] &&continue# Here we have confirmed that the directory contains a solution file
solution_dir="$dir"# Get the path to the solution file in the .NET solution folder
solution_file=$(find "$dir" -type f -name '*.sln')echo"[PRE-COMMIT] Formatting $solution_file"
dotnet husky run --name dotnet-format-staged-files --args "$solution_dir"done
We pass the solution directory as argument, because dotnet format requires the workspace to be provided as command line argument whenever dotnet format is executed from a directory that does not contain a solution file (i.e. the root of our repository).
To conclude, if we could use the ${args} variable in the "include" glob pattern, dotnet format would only be executed for solutions that contain staged files. Which saves a lot of time for repositories with multiple solutions!
Thanks for reading, and I'd love to hear what you think of this.
Best,
Thijmen
The text was updated successfully, but these errors were encountered:
Discussed in #113
Originally posted by ThijmenDam May 21, 2024
Hi @alirezanet and contributors, first of all I'd like to thank you for this very useful package.
So, our team would greatly benefit from the possibility of using variables in the "include" glob pattern. For example:
The reason this would be very useful for our team is performance. To elaborate, some of our repositories contain multiple solutions, and without variables in the "include" glob pattern, we are not able to execute
dotnet format
only for the solutions that contain staged files. This means thatdotnet format
is executed for every solution, even if there are no staged files from that solution (which slows down the pre-commit hook by a lot).To illustrate, consider the following pre-commit hook:
We pass the solution directory as argument, because
dotnet format
requires the workspace to be provided as command line argument wheneverdotnet format
is executed from a directory that does not contain a solution file (i.e. the root of our repository).To conclude, if we could use the
${args}
variable in the "include" glob pattern,dotnet format
would only be executed for solutions that contain staged files. Which saves a lot of time for repositories with multiple solutions!Thanks for reading, and I'd love to hear what you think of this.
Best,
Thijmen
The text was updated successfully, but these errors were encountered: