* Git hooks format

* Update build.ps1

Co-authored-by: Allison Chou <allichou@microsoft.com>

Co-authored-by: Allison Chou <allichou@microsoft.com>
This commit is contained in:
Ryan Brandenburg 2021-01-21 13:22:04 -08:00 коммит произвёл GitHub
Родитель 922be0ff0d
Коммит e510588cfd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 41 добавлений и 0 удалений

15
.githooks/pre-commit Executable file
Просмотреть файл

@ -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

26
build.ps1 Normal file
Просмотреть файл

@ -0,0 +1,26 @@
# 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
& $PSScriptRoot\eng\common\Build.ps1 -restore -build -pack $args
function ExitWithExitCode([int] $exitCode) {
if ($ci -and $prepareMachine) {
Stop-Processes
}
exit $exitCode
}
ExitWithExitCode $LASTEXITCODE