Skip to content

Instantly share code, notes, and snippets.

@doodyparizada
Created August 5, 2014 07:30
Show Gist options
  • Save doodyparizada/6e62bfed2cf49a2435c3 to your computer and use it in GitHub Desktop.
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
#!/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