-
-
Save soorepalli/d6894ae076b8666c544ad0e0ac21a654 to your computer and use it in GitHub Desktop.
python script for setting up git directories on remote servers
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 | |
# updated March 31, 2013 | |
# updated December 1, 2013 | |
# - print out resulting command | |
# | |
import os | |
import sys | |
def main(): | |
if len(sys.argv) != 3: | |
print """ | |
Usage: python create_repo.py repo.git /your/checkout/dirctory | |
Locally, run: | |
git remote add web ssh://[email protected]/home/jkeesh/repos/<repo.git> | |
To deploy, use: | |
git push web master | |
""" | |
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') | |
# Print a command to run next. | |
print "\n\nNow run this command on your local repository\n\n" | |
cmd = 'git remote add web ssh://[email protected]/home/jkeesh/repos/' + repo | |
print cmd | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment