Created
August 5, 2014 07:30
-
-
Save doodyparizada/6e62bfed2cf49a2435c3 to your computer and use it in GitHub Desktop.
a python script for prepare-commit-msg that extracts the branch name and inserts it as the first word of the commit message title
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/python | |
import commands | |
import sys | |
import fileinput | |
def get_task_name(branch): | |
task = branch.rsplit("/",1)[-1] | |
task = task.split("_")[0] | |
if task.count('-') > 1: | |
task = '-'.join(task.split('-')[:2]) | |
return task | |
branch_name = get_task_name(commands.getoutput("git symbolic-ref -q HEAD")) | |
for line in fileinput.input(sys.argv[1], inplace=1): | |
if fileinput.isfirstline() and line.strip() == '': | |
print branch_name | |
print line, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment