Created
April 9, 2014 12:45
-
-
Save smotesko/10265723 to your computer and use it in GitHub Desktop.
git commit helper for my current job
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/env php | |
<?php | |
// filename: refscommit | |
/** | |
* Our git approach is to name branches like "feature/123-description" and commits like | |
* "refs #123 commitmessage". | |
* This scripts prepends "refs #number " to the commit message if current git branch is | |
* "feature/number.*". | |
* So it helps you by inserting your feature number into the commit message. | |
* Use it as `refscommit commit_message`. | |
*/ | |
function get_first_line($command) { | |
$output = array(); | |
$status = 0; | |
exec($command, $output, $status); | |
if ($status > 0) | |
throw new Exception('Command `'.$command.'` returned status '.$status, 1); | |
return $output[0]; | |
} | |
function get_feature_number() { | |
$line = get_first_line('git branch'); | |
$matches = array(); | |
if (!preg_match('/^\*\sfeature\/(\d+).+$/', $line, $matches)) | |
throw new Exception("Can't find the feature number", 1); | |
return $matches[1]; | |
} | |
if (!$argv[1]) { | |
echo("Usage: refscommit commit_message\n"); | |
exit(1); | |
} | |
$feature_number = get_feature_number(); | |
$commitcommand = "git commit -m \"refs #$feature_number {$argv[1]}\""; | |
echo "Executing `$commitcommand`\n"; | |
passthru($commitcommand); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment