Python script to create a remote git repo that checks out the latest commit with a post-receive 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
# | |
# This script creates a repository and sets it up with a post receive | |
# hook that checks out the code to the desired directory. | |
# | |
# Really nice for setting up an easy way to push code to a remote | |
# server without lots of overhead. | |
# | |
# After running this script simply add a remote locally like | |
# | |
# git remote add web ssh://you@server/path/to/repo.git | |
# | |
# Then pushing to the remote is as easy as | |
# | |
# git push web | |
# | |
# Jeremy Keeshin September 23, 2012 | |
# | |
import os | |
import sys | |
def main(): | |
if len(sys.argv) != 3: | |
print """ | |
Usage: python create_repo.py repo_name.git /your/checkout/dirctory | |
""" | |
sys.exit(1) | |
else: | |
repo = sys.argv[1] | |
checkout_dir = sys.argv[2] | |
# Make the git directory | |
os.system('mkdir %s' % repo) | |
os.chdir('%s' % repo) | |
# Initialize a new bare repo | |
os.system('git init --bare') | |
txt = """#!/bin/sh | |
GIT_WORK_TREE=%s git checkout -f""" % checkout_dir | |
# Write the post-receive hook | |
hook = open('./hooks/post-receive', 'w') | |
hook.write(txt) | |
hook.close() | |
# Make it executable | |
os.system('chmod +x ./hooks/post-receive') | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment