Created
January 1, 2018 21:54
-
-
Save Staggerlee011/7c58bd89d70b802024d34afc0dbdd51d to your computer and use it in GitHub Desktop.
Example of a pre-commit hook using powershell used in Blog post:
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
write-output "This is a pre-commit powershell call" | |
write-output "=======================================" | |
Import-Module -Name PSScriptAnalyzer | |
$changes = git diff --name-only | |
$output = @() | |
foreach ($change in $changes) | |
{ | |
write-output "Running ScriptAnalyzer against: $change" | |
$winPath = $change.replace("/", "\") | |
$winPath = ".\$winPath" | |
$out = Invoke-ScriptAnalyzer -Path $winPath | |
$output += $out | |
} | |
write-output "=======================================" | |
if ($output.Count -ne 0) | |
{ | |
Write-Output "Basic scripting errors were found in updated scripts. fix or use git commit --no-verify" | |
$output.Message | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment