Skip to content

Instantly share code, notes, and snippets.

@tomykaira
Last active August 29, 2015 14:07
Show Gist options
  • Save tomykaira/73b3de91b5d8526b5cf2 to your computer and use it in GitHub Desktop.
Save tomykaira/73b3de91b5d8526b5cf2 to your computer and use it in GitHub Desktop.
Prepare local git repository in seconds
Usage
- clone this
- ./initrepo foo.git
- ./easygit.rb
- git clone http://localhost:8080/foo.git
#!/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
#!/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