Skip to content

Instantly share code, notes, and snippets.

@bao-qian
Created July 20, 2017 09:55
Show Gist options
  • Save bao-qian/564b7f06e4ea9ac2eb8e0024fa63d37f to your computer and use it in GitHub Desktop.
Save bao-qian/564b7f06e4ea9ac2eb8e0024fa63d37f to your computer and use it in GitHub Desktop.
git hook for particular branch
#!/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()
@bao-qian
Copy link
Author

change expect to branch
and
filename to log file

@bao-qian
Copy link
Author

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