Created
July 11, 2014 14:47
-
-
Save caryfitzhugh/750daa01e1aa42aab939 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
#!/usr/bin/php | |
<?php | |
# Git Prepare Commit Message Hook Script | |
# | |
# Location: <repository>/.git/hooks/prepare-commit-msg | |
# | |
# This script will automatically add the correct | |
# Pivotal Ticket ID to the beginning of each commit message | |
# When the branch ID is starts with the Pivotal Message ID. | |
# It can be overridden if specified in the message. | |
# | |
# Example: | |
# | |
# 1234567_branch_name => '[#1234567] commit message' | |
# | |
# @author Tamas Kalman <[email protected]> | |
$messageFile = $argv[1]; | |
$message = file_get_contents($messageFile); | |
$currentBranchName = exec('git rev-parse --abbrev-ref HEAD'); | |
print($currentBranchName); | |
$branchPivotalPattern = '/^([0-9]{1,16})-/'; | |
preg_match($branchPivotalPattern, $currentBranchName, $matches); | |
$branchPivotalId = (isset($matches[1])) ? $matches[1] : null; | |
if ($branchPivotalId !== null) { | |
$message = sprintf('[#%s] %s', $branchPivotalId, $message); | |
file_put_contents($messageFile, $message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment