Skip to content

Instantly share code, notes, and snippets.

@tomtobac
Last active October 30, 2017 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomtobac/dc6dcd2cb09e95249d7d39fec6a73506 to your computer and use it in GitHub Desktop.
Save tomtobac/dc6dcd2cb09e95249d7d39fec6a73506 to your computer and use it in GitHub Desktop.
[GIT-HOOK] attach task to the commit.
#!/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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment