Created
June 1, 2018 08:37
-
-
Save tobyS/7fc8002e786345af2aa8d13f74de35ce to your computer and use it in GitHub Desktop.
Ticket number prefix without branch (reads .ticket file)
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/php | |
# FILE: .git/hooks/commit-msg | |
<?php | |
$commitMessages = file($argv[1]); | |
if (preg_match('(^[0-9]+:\s*$)', $commitMessages[0])) { | |
echo "Empty commit message, aborting.\n"; | |
exit(1); | |
} |
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/php | |
# FILE: .git/hooks/prepare-commit-msg | |
<?php | |
if (isset($argv[2])) { | |
echo "Special commit type. Won't edit message.\n"; | |
exit(0); | |
} | |
if (!file_exists('.ticket')) { | |
echo "No .ticket file found. Won't edit message.\n"; | |
exit(0); | |
} | |
$commitFile = $argv[1]; | |
$ticketNumber = trim(file_get_contents('.ticket')); | |
if ($ticketNumber === '') { | |
echo "No ticket number in ticket file. Won't edit message.\n"; | |
exit(0); | |
} | |
file_put_contents( | |
$commitFile, | |
$ticketNumber . ': ' . file_get_contents($commitFile) | |
); | |
echo "Prefixed commit message with ticket number {$ticketNumber}.\n"; | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
git config --global core.editor "vim '+ normal \$'"
makes your VIM start at the end of the line (aka behind the ticket number) for editing the commit message.