-
-
Save stucox/7704057 to your computer and use it in GitHub Desktop.
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/env python | |
""" | |
To enable save as /yourproject/.git/hooks/prepare-commit-msg and make executable: chmod +rx prepare-commit-msg | |
""" | |
import sys | |
from subprocess import check_output | |
def get_ticket_number(): | |
branch_name = check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) | |
return branch_name.split('-')[1] | |
def prepend_to_file(marker): | |
with open(sys.argv[1], 'r') as message_file: | |
lines = message_file.readlines() | |
lines[0] = marker + lines[0] | |
with open(sys.argv[1], 'w') as message_file: | |
message_file.write(''.join(lines)) | |
if __name__ == '__main__': | |
marker = '\n\n#[touch:%s]' % get_ticket_number() | |
prepend_to_file(marker) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment