Skip to content

Instantly share code, notes, and snippets.

@automaticalldramatic
Forked from six0h/post-update
Created November 10, 2016 11:37
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 automaticalldramatic/392006d719fac0b7c494e797d1ef93f8 to your computer and use it in GitHub Desktop.
Save automaticalldramatic/392006d719fac0b7c494e797d1ef93f8 to your computer and use it in GitHub Desktop.
Git Post-Update hook that checks for changes to composer.lock, and fires a composer install if required.
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""A post-update Git hook to execute `composer install` when composer.json changes
:Author: Cody Halovich
:Company: HootSuite Media Inc.
"""
import subprocess
import string
import os
HOOK_DIR = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.dirname(os.path.dirname(HOOK_DIR))
def getChangeList():
"""Retrieve the active Git change-list
"""
files = subprocess.Popen(['git', 'diff', '--name-status', 'master@{1}'], stdout=subprocess.PIPE)
results = files.stdout.read()
return results
def main():
"""Update composer if `composer.lock` exists in the active change-list
"""
if getChangeList().find('composer.lock') > 0:
os.chdir(ROOT_DIR)
subprocess.Popen([ROOT_DIR + 'composer.phar', 'install'])
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment