Created
October 24, 2023 19:39
-
-
Save huskercane/8bc98989e070c450456149ff23ff8815 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
param ( | |
[string]$COMMIT_MSG_FILE, | |
[string]$COMMIT_SOURCE, | |
[string]$SHA1 | |
) | |
# Get the current branch name | |
$BRANCH_NAME = (git rev-parse --abbrev-ref HEAD 2>$null) | |
# Ensure BRANCH_NAME is not empty and is not in a detached HEAD state (i.e. rebase). | |
# SKIP_PREPARE_COMMIT_MSG may be used as an escape hatch to disable this hook, | |
# while still allowing other githooks to run. | |
if (![string]::IsNullOrEmpty($BRANCH_NAME) -and $BRANCH_NAME -ne "HEAD" -and $env:SKIP_PREPARE_COMMIT_MSG -ne "1") { | |
# Use regex to extract "SPAOP-1363" | |
$parsed_string = $BRANCH_NAME -replace '.*\/', '' | |
# Use regex to further refine the result | |
$PREFIX_IN_COMMIT = $parsed_string -replace '(.+?-.+?)-.*', '$1' | |
# Ensure PREFIX exists in BRANCH_NAME and is not already present in the commit message | |
if (![string]::IsNullOrEmpty($env:PREFIX) -and $PREFIX_IN_COMMIT -notmatch '\d') { | |
$content = Get-Content -Path $COMMIT_MSG_FILE | |
$content[0] = $content[0] + " [$env:PREFIX] " | |
$content | Set-Content -Path $COMMIT_MSG_FILE | |
} | |
Add-Content -Path $COMMIT_MSG_FILE -Value "[$PREFIX_IN_COMMIT]" | |
} |
This file contains hidden or 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
#!/bin/sh | |
echo | |
exec powershell.exe -ExecutionPolicy RemoteSigned -File '.\.git\hooks\prepare-commit-msg.ps1' $* | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment