Skip to content

Added dotnet-format pre commit hook. #27712

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
merged 1 commit into from
Jan 19, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
LC_ALL=C

# Select files to format
FILES=$(git show --name-only --pretty="")
[ -z "$FILES" ] && exit 0

# Format all selected files with dotnet-format
echo "dotnet-format: Formatting changed source files.."
echo "$FILES" | cat | xargs | sed -e 's/ /,/g' | xargs dotnet-format --folder . --include >/dev/null
echo "dotnet-format: $(git diff --cached --numstat | wc -l) file(s) formatted."

# Add files to staging
echo "$FILES" | xargs git add
exit 0
18 changes: 18 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,24 @@ if (-not $foundJdk -and $RunBuild -and ($All -or $BuildJava) -and -not $NoBuildJ
Write-Error "Could not find the JDK. Either run $PSScriptRoot\eng\scripts\InstallJdk.ps1 to install for this repo, or install the JDK globally on your machine (see $PSScriptRoot\docs\BuildFromSource.md for details)."
}

# Check dotnet-format is installed or not
$dotnetFormat = Get-Command dotnet-format -ErrorAction Ignore -CommandType Application

if($dotnetFormat)
{
Write-Host -f Magenta "dotnet format tool is already installed."
}
else
{
Write-Host -f Magenta "Installing dotnet-format tool.."
& dotnet tool install -g dotnet-format
}

# We need to change default git hooks directory as .git folder is not tracked. And by default hooks are stored in .git/hooks folder.
# So we are setting git hooks default directory to .githooks, so that we can track and version the git hooks.
& git config core.hooksPath .githooks


# Initialize global variables need to be set before the import of Arcade is imported
$restore = $RunRestore

Expand Down