Created
May 9, 2024 00:59
-
-
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.
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
#!/usr/bin/env sh | |
pwsh -noprofile -F .git/hooks/pre-commit.ps1 |
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
$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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Powershell core is required.