#!/usr/bin/env python
""" to enable this hook:
replace the file prepare-commit-msg.sample
under (.git/hooks/) without the sample preffix.
Eg: We're in the branch: feature/ABC-123-fix-this-ASAP
when we push our commit it will be refactored as "[ABC-123] my commit"
"""
import subprocess, sys
commit_msg_filepath = sys.argv[1]
try:
branch = subprocess.check_output(['git', 'symbolic-ref', '--short' ,'HEAD'])
task = '[' + '-'.join(branch.split('/')[1].split('-')[:2]) + '] '
except:
task = '';
with open(commit_msg_filepath, 'r+') as f:
previous_commit = f.read()
commit = (task + previous_commit).strip()
f.seek(0)
f.write(commit)