Permalink
Browse files

Merged latest.

  • Loading branch information...
2 parents 4c0ed51 + a7d3c24 commit aeba310d792840faeb27bdcac6a4ef446636ac8f @ntalbott ntalbott committed May 31, 2008
Showing with 37 additions and 19 deletions.
  1. +3 −2 bin/gitjour
  2. +33 −16 lib/gitjour/application.rb
  3. +1 −1 lib/gitjour/version.rb
View
@@ -21,8 +21,9 @@ options = CoolOptions.parse!("[options] command [name]") do |o|
o.desc "\n"
o.desc "Options:"
- o.on 'port PORT', "Pass to serve to serve on a different port.", 9418
- o.on 'verbose', "Verbose output.", false
+ o.on '(P)port PORT', "Pass to serve to serve on a different port.", 9418
+ o.on 'path PATH', "Path to serve."
+ o.on 'verbose', "Verbose output.", false
o.after do |result|
(result.command = ARGV.shift) || o.error("Command is required.")
View
@@ -5,50 +5,69 @@
module Gitjour
GitService = Struct.new(:name, :host, :port, :description)
+
class Application
class << self
def run(options)
@@verbose = options.verbose
case options.command
when "list"
- service_list.each do |service|
- puts "=== #{service.name} on #{service.host} ==="
- puts " gitjour clone #{service.name}"
- puts " #{service.description}" if service.description && service.description != '' && service.description !~ /^Unnamed repository/
- puts
- end
+ list
when "clone"
clone(options.name)
when "serve"
- serve(options.name, options.port)
+ serve(options.name, options.path, options.port)
+ when "remote"
+ remote(options.name)
else
help
end
end
-
+
private
+ def list
+ service_list.each do |service|
+ puts "=== #{service.name} on #{service.host} ==="
+ puts " gitjour clone #{service.name}"
+ puts " #{service.description}" if service.description && service.description != '' && service.description !~ /^Unnamed repository/
+ puts
+ end
+ end
+
+ def get_host_and_share(repository_name)
+ name_of_share = repository_name || fail("You have to pass in a name")
+ host = service_list(name_of_share).detect{|service| service.name == name_of_share}.host rescue exit_with!("Couldn't find #{name_of_share}")
+ system("git clone git://#{host}/ #{name_of_share}/")
+ [host, name_of_share]
+ end
+
def clone(name)
service = service_list(name).detect{|service| service.name == name} rescue exit_with!("Couldn't find #{name}")
cl("git clone git://#{service.host}:#{service.port}/ #{name}/")
end
+ def remote(repository_name,*rest)
+ host, name_of_share = get_host_and_share(repository_name)
+ system("git remote add #{name_of_share} git://#{host}/")
+ end
+
def serve(path, port)
path ||= Dir.pwd
path = File.expand_path(path)
File.exists?("#{path}/.git") ? announce_repo(path, port) : Dir["#{path}/*"].each_with_index{|dir,i| announce_repo(dir, port+i) if File.directory?(dir)}
cl("git-daemon --verbose --export-all --port=#{port} --base-path=#{path} --base-path-relaxed")
end
-
+
def exit_with!(message)
STDERR.puts message
exit!
end
-
+
def service_list(looking_for = nil)
wait_seconds = 5
- service_list = Set.new
+ service_list = Set.new
waiting_thread = Thread.new { sleep wait_seconds }
service = DNSSD.browse "_git._tcp" do |reply|
@@ -61,13 +80,13 @@ def service_list(looking_for = nil)
end
puts "Gathering for up to #{wait_seconds} seconds..."
waiting_thread.join
- service.stop
+ service.stop
service_list
end
- def announce_repo(path, port)
+ def announce_repo(name, path, port)
return unless File.exists?("#{path}/.git")
- name = "#{File.basename(path)}"
+ name = share_name || File.basename(path)
tr = DNSSD::TextRecord.new
tr['description'] = File.read(".git/description") rescue "a git project"
DNSSD.register(name, "_git._tcp", 'local', port, tr.encode) do |register_reply|
@@ -83,8 +102,6 @@ def cl(command)
end
end
end
-
-
end
end
View
@@ -1,7 +1,7 @@
module Gitjour #:nodoc:
module VERSION #:nodoc:
MAJOR = 6
- MINOR = 0
+ MINOR = 1
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')

0 comments on commit aeba310

Please sign in to comment.