Created
July 20, 2017 09:55
-
-
Save bao-qian/564b7f06e4ea9ac2eb8e0024fa63d37f to your computer and use it in GitHub Desktop.
git hook for particular branch
This file contains hidden or 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 python3 | |
import time | |
import sys | |
import fileinput | |
import os.path | |
import time | |
import json | |
def log(*args, **kwargs): | |
format = '%H:%M:%S' | |
value = time.localtime(int(time.time())) | |
dt = time.strftime(format, value) | |
print(dt, *args, **kwargs) | |
filename = '{}.log'.format(__file__) | |
with open(filename, 'a', encoding='utf-8') as f: | |
print(dt, *args, file=f, **kwargs) | |
def process_branch(branch): | |
expect = 'branch_name' | |
if expect in branch: | |
log('found correct branch', branch) | |
def main(): | |
log('argv', sys.argv) | |
for line in fileinput.input(): | |
log('line', line) | |
parts = line.split() | |
branch = parts[2] | |
process_branch(branch) | |
if __name__ == '__main__': | |
print('begin post receive') | |
main() |
link to /git/*.git/hooks/post-receive
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
change expect to branch
and
filename to log file