#!/usr/bin/env python
import sys, re
from subprocess import check_output

commit_msg_filepath = sys.argv[1]
story_id = check_output(['git', 'story']).decode('UTF-8').strip()

if story_id is None:
    exit(0)

with open(commit_msg_filepath, 'r+') as fh:
    commit_msg = fh.read()
    if commit_msg.startswith('['+story_id+']'):
        exit(0)
    fh.seek(0, 0)
    fh.write('[%s] %s' % (story_id, commit_msg))
