Skip to content

Instantly share code, notes, and snippets.

@RickyLin
Created May 9, 2024 00:59
Show Gist options
  • Save RickyLin/eae89f8a7371ff4b75f63ca22ca450e2 to your computer and use it in GitHub Desktop.
Save RickyLin/eae89f8a7371ff4b75f63ca22ca450e2 to your computer and use it in GitHub Desktop.
Git Hooks: Check the "do not commit" string in committed content and cancel the commit if found.
#!/usr/bin/env sh
pwsh -noprofile -F .git/hooks/pre-commit.ps1
$DoNotCommit = git diff --cached | Select-String -Pattern "do not commit" | Out-String
if (![string]::IsNullOrEmpty($DoNotCommit))
{
Write-Host ("""Do not commit"" was found, the commit was cancelled:") -ForegroundColor Red
$DoNotCommit = $DoNotCommit.TrimStart().TrimStart(' ', '+')
Write-Host ($DoNotCommit) -ForegroundColor Red
exit 1
}
@RickyLin
Copy link
Author

RickyLin commented May 9, 2024

Powershell core is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment