Last active
December 10, 2015 16:38
-
-
Save shalakhin/4461862 to your computer and use it in GitHub Desktop.
prepare-commit-msg git hook
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 | |
# requirements: GitPython | |
# version 0.1 | |
import git | |
import os | |
import sys | |
def get_branch(): | |
""" | |
Get current branch with GitPython | |
""" | |
path = os.getcwd() | |
repo = git.Repo(path) | |
return repo.head.reference.name | |
def prepare_commit_msg(): | |
""" | |
- Prepend "<branch name>, " | |
""" | |
branch = get_branch() | |
msg = "{0}, ".format(branch.lower().capitalize()) | |
# for prepare-commit-msg the second parameter | |
# is the path to commit message | |
path = sys.argv[1] | |
try: | |
with open(path, 'w') as f: | |
content = f.read() | |
f.write("{0}{1}".format(msg, content)) | |
except: | |
pass | |
if __name__ == '__main__': | |
prepare_commit_msg() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment