Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Forked from lazyatom/git-serve
Created February 13, 2009 19:13
Show Gist options
  • Save lukeredpath/64052 to your computer and use it in GitHub Desktop.
Save lukeredpath/64052 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
if ARGV.empty?
puts "Usage: #{__FILE__} <repository> <repository> ..."
exit -1
end
created_flags = []
ARGV.each do |repo|
if File.exist?(File.join(Dir.pwd, repo))
flag = File.join(Dir.pwd, repo, ".git", "git-daemon-export-ok")
unless File.exist?(flag)
FileUtils.touch(flag)
created_flags << flag
end
else
puts "Cannot find repository called '#{repo}' in the current directory; skipping"
end
end
def cleanup(flags)
flags.each do |flag|
File.delete(flag)
end
end
Signal.trap('INT') do
puts "Stopping server"
cleanup(created_flags)
exit 0
end
cmd = "git daemon --base-path=#{Dir.pwd}"
puts "Serving... [#{cmd}]"
`#{cmd}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment