Skip to content

Instantly share code, notes, and snippets.

@Staggerlee011
Created January 1, 2018 21:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Staggerlee011/7c58bd89d70b802024d34afc0dbdd51d to your computer and use it in GitHub Desktop.
Save Staggerlee011/7c58bd89d70b802024d34afc0dbdd51d to your computer and use it in GitHub Desktop.
Example of a pre-commit hook using powershell used in Blog post:
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