Skip to content

Instantly share code, notes, and snippets.

@N-McA
Created January 27, 2019 14:06
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 N-McA/de6c3ba3700c8e43680a22a32f3d7cf5 to your computer and use it in GitHub Desktop.
Save N-McA/de6c3ba3700c8e43680a22a32f3d7cf5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import subprocess
import shlex
import os
from pathlib import Path
def chdir_to_script_location():
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
def run(cmd, ignore_fail=False):
check = not ignore_fail
return subprocess.run(
shlex.split(cmd), check=check, stdout=subprocess.PIPE
).stdout.decode("UTF-8")
def link_hook(file, hook_name):
run('rm ./.git/hooks/{}'.format(hook_name), ignore_fail=True)
cmd = "ln -s {relpath} .git/hooks/{hook_name}"
run(cmd.format(
relpath=os.path.relpath(file, '.git/hooks/'),
hook_name=hook_name,
))
if __name__ == "__main__":
chdir_to_script_location()
link_hook('./hooks/no-commits-on-prod.py', 'pre-commit')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment