0
-require 'gitjour/application'
0
+Thread.abort_on_exception = true
0
+ GitService = Struct.new(:name, :host, :port, :description)
0
+ service_list.each do |service|
0
+ puts "=== #{service.name} on #{service.host}:#{service.port} ==="
0
+ puts " gitjour clone #{service.name}"
0
+ if service.description != '' && service.description !~ /^Unnamed repository/
0
+ puts " #{service.description}"
0
+ def clone(repository_name, *rest)
0
+ dir = rest.shift || repository_name
0
+ exit_with! "ERROR: Clone directory '#{dir}' already exists."
0
+ puts "Cloning '#{repository_name}' into directory '#{dir}'..."
0
+ unless service = locate_repo(repository_name)
0
+ exit_with! "ERROR: Unable to find project named '#{repository_name}'"
0
+ puts "Connecting to #{service.host}:#{service.port}"
0
+ system "git clone git://#{service.host}:#{service.port}/ #{dir}/"
0
+ def remote(repository_name, *rest)
0
+ dir = rest.shift || repository_name
0
+ service = locate_repo repository_name
0
+ system "git remote add #{dir} git://#{service.host}:#{service.port}/"
0
+ def serve(path=Dir.pwd, *rest)
0
+ path = File.expand_path(path)
0
+ name = rest.shift || File.basename(path)
0
+ port = rest.shift || 9418
0
+ # If the name starts with ^, then don't apply the prefix
0
+ prefix = `git config --get gitjour.prefix`.chomp
0
+ prefix = ENV["USER"] if prefix.empty?
0
+ name = [prefix, name].compact.join("-")
0
+ if File.exists?("#{path}/.git")
0
+ announce_repo(path, name, port.to_i)
0
+ Dir["#{path}/*"].each do |dir|
0
+ if File.directory?(dir)
0
+ name = File.basename(dir)
0
+ announce_repo(dir, name, 9418)
0
+ `git-daemon --verbose --export-all --port=#{port} --base-path=#{path} --base-path-relaxed`
0
+ puts "Gitjour #{Gitjour::VERSION::STRING}"
0
+ puts "Serve up and use git repositories via Bonjour/DNSSD."
0
+ puts "\nUsage: gitjour <command> [args]"
0
+ puts " Lists available repositories."
0
+ puts " clone <project> [<directory>]"
0
+ puts " Clone a gitjour served repository."
0
+ puts " serve <path_to_project> [<name_of_project>] [<port>] or"
0
+ puts " <path_to_projects>"
0
+ puts " Serve up the current directory or projects via gitjour."
0
+ puts " The name of your project is automatically prefixed with"
0
+ puts " `git config --get gitjour.prefix` or your username (preference"
0
+ puts " in that order). If you don't want a prefix, put a ^ on the front"
0
+ puts " of the name_of_project (the ^ is removed before announcing)."
0
+ puts " remote <project> [<name>]"
0
+ puts " Add a Bonjour remote into your current repository."
0
+ puts " Optionally pass name to not use pwd."
0
+ def exit_with!(message)
0
+ class Done < RuntimeError; end
0
+ def discover(timeout=5)
0
+ waiting_thread = Thread.current
0
+ dns = DNSSD.browse "_git._tcp" do |reply|
0
+ DNSSD.resolve reply.name, reply.type, reply.domain do |resolve_reply|
0
+ service = GitService.new(reply.name,
0
+ resolve_reply.text_record['description'].to_s)
0
+ puts "Gathering for up to #{timeout} seconds..."
0
+ discover { |obj| list << obj }
0
+ def announce_repo(path, name, port)
0
+ return unless File.exists?("#{path}/.git")
0
+ tr = DNSSD::TextRecord.new
0
+ tr['description'] = File.read("#{path}/.git/description") rescue "a git project"
0
+ DNSSD.register(name, "_git._tcp", 'local', port, tr.encode) do |rr|
0
+ puts "Registered #{name} on port #{port}. Starting service."
Comments
No one has commented yet.