-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dotnet format no longer adds all files to git (#34)
- Loading branch information
1 parent
be4401b
commit affbdfe
Showing
3 changed files
with
32 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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,6 @@ | ||
# Auto detect text files and perform LF normalization | ||
*.cs text diff=csharp eol=lf | ||
*.cshtml text diff=html eol=lf | ||
*.csx text diff=csharp eol=lf | ||
*.sln text eol=lf | ||
*.csproj text eol=lf |
This file contains 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 |
---|---|---|
@@ -1,7 +1,27 @@ | ||
#!/bin/sh | ||
|
||
# Boilerplate husky | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
dotnet format -v diag | ||
# Find all c# related staged files, before doing anything | ||
FILES_TO_BE_FORMATTED=$(git diff --staged --name-only | grep -E '\.(cs|csproj|sln)$' || echo '') | ||
|
||
if [ -z $FILES_TO_BE_FORMATTED ]; then | ||
echo "No .NET files to format, skipping dotnet format..." | ||
exit 0 | ||
fi | ||
|
||
echo "Files to be formatted:" | ||
for file in $FILES_TO_BE_FORMATTED; do | ||
echo " - $file" | ||
done | ||
echo "" # new-line for clarity | ||
|
||
# Format c# related staged files only | ||
echo $FILES_TO_BE_FORMATTED | xargs dotnet format -v diag Aplib.Net.sln --include | ||
|
||
# Add all formatted files again, to add changed files | ||
echo $FILES_TO_BE_FORMATTED | xargs git add | ||
|
||
echo -e "\nDone formatting files!\nCheck the log to find out if files have changed.\n" | ||
|
||
# Add any changes made by dotnet format to the commit | ||
git add . |