Last active
August 29, 2015 14:07
-
-
Save tomykaira/73b3de91b5d8526b5cf2 to your computer and use it in GitHub Desktop.
Prepare local git repository in seconds
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
Usage | |
- clone this | |
- ./initrepo foo.git | |
- ./easygit.rb | |
- git clone http://localhost:8080/foo.git |
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
#!/usr/bin/env ruby | |
require 'webrick' | |
server = WEBrick::HTTPServer.new({ | |
:DocumentRoot => '.', | |
:Port => '8080', | |
:CGIInterpreter => '/usr/libexec/git-core/git-http-backend' | |
}) | |
class MyCgiHandler < WEBrick::HTTPServlet::CGIHandler | |
def do_GET(req, res) | |
class << req | |
def meta_vars | |
super.merge( | |
'GIT_PROJECT_ROOT' => File.expand_path(__FILE__ + '/..'), | |
'GIT_HTTP_EXPORT_ALL' => 'true' | |
) | |
end | |
end | |
super | |
end | |
alias do_POST do_GET | |
end | |
server.mount('/', MyCgiHandler, '/usr/libexec/git-core/git-http-backend') | |
['INT', 'TERM'].each {|signal| | |
Signal.trap(signal){ server.shutdown } | |
} | |
server.start |
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
#!/bin/sh -e | |
if [ -z $1 ]; then | |
echo "Give repo name including .git (ex. foo.git)" | |
exit 1 | |
fi | |
mkdir $1 | |
cd $1 | |
git init --bare | |
git config http.getanyfile true | |
git config http.uploadpack true | |
git config http.receivepack true | |
cd - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment