Skip to content
This repository has been archived by the owner on Jan 23, 2018. It is now read-only.

Commit

Permalink
began the project
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Jul 23, 2008
0 parents commit 9b7ec9e
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 0 deletions.
6 changes: 6 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
=== 0.0.1 / 2008-07-22

* 1 major enhancement

* Birthday!

11 changes: 11 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
COPYING
History.txt
Manifest.txt
README.txt
Rakefile
bin/conspire
lib/conspire.rb
lib/conspire/conspirator.rb
lib/conspire/gitjour_exts.rb
lib/conspire/support/conspire.el
test/test_conspire.rb
15 changes: 15 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- ruby -*-

require 'rubygems'
require 'hoe'
require './lib/conspire.rb'

Hoe.new('conspire', Conspire::VERSION) do |p|
p.developer('Phil Hagelberg', 'technomancy@gmail.com')

# Get these from github:
p.extra_deps << 'nogoth-gitjour'
p.extra_deps << 'mojombo-grit'
end

# vim: syntax=Ruby
6 changes: 6 additions & 0 deletions bin/conspire
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../lib/conspire'

# For now...
Conspire.send *ARGV
41 changes: 41 additions & 0 deletions lib/conspire.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$LOAD_PATH << File.dirname(__FILE__)
require 'set'
require 'rubygems'
require 'gitjour'
require 'mojombo-grit'

require 'conspire/gitjour_exts'
require 'conspire/conspirator'

module Conspire
VERSION = '0.0.1'
DEFAULT_OPTIONS = { :port => 7456, :path => Dir.pwd }
SERVICE_NAME = 'conspire'

@conspirators = Set.new

module_function

def start(options = {})
options = DEFAULT_OPTIONS.merge(options)
@repo = Grit::Repo.new(options[:path])
@thread = Thread.new do
Gitjour::Application.serve(options[:path], SERVICE_NAME, options[:port])
end
at_exit { @thread.join }
end

def discover
Gitjour::Application.service_list('_git._tcp').each do |service|
next unless service.name == SERVICE_NAME
# No-op if we've got it already, since @conspirators is a Set
@conspirators << Conspirator.new(service.host, service.port)
end
end

def sync_all
@conspirators.map{ |s| s.sync(@repo.path) }
end

def conspirators; @conspirators end
end
25 changes: 25 additions & 0 deletions lib/conspire/conspirator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Conspire
class Conspirator
attr_accessor :last_synced

def initialize(host, port)
@host, @port = remote.split(':')
@port ||= DEFAULT_OPTIONS[:port]
end

def to_s
"#{@host}:#{@port}"
end

def sync(path)
`cd #{path} && git pull #{url}`
@last_synced = Time.now
end

def url; "git://#{@host}:#{@port}/conspire" end

def eql?(other)
self.to_s == other.to_s
end
end
end
7 changes: 7 additions & 0 deletions lib/conspire/gitjour_exts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Gitjour
class Application
class << self
public :serve, :service_list
end
end
end
58 changes: 58 additions & 0 deletions test/test_conspire.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'rubygems'
begin
gem 'miniunit'
rescue LoadError; end

require 'test/unit'
require 'fileutils'
require File.dirname(__FILE__) + '/../lib/conspire'

REMOTE_SPACE = File.dirname(__FILE__) + '/remote-space'
LOCAL_SPACE = File.dirname(__FILE__) + '/local-space'

module Conspire
def self.reset!
@conspirators = []
@thread && @thread.kill
end
end

class TestConspire < Test::Unit::TestCase
def setup
FileUtils.mkdir_p(REMOTE_SPACE)
File.open(REMOTE_SPACE + '/file', 'w') { |f| f.puts "hello world." }
`cd #{REMOTE_SPACE}; git init; git add file; git commit -m "init"`

FileUtils.mkdir_p(LOCAL_SPACE)
`cd #{LOCAL_SPACE}; git init`

@remote_thread = Thread.new do
Gitjour::Application.serve(REMOTE_SPACE, Conspire::SERVICE_NAME, 7458)
end

Conspire.start(:port => 7457,
:path => "#{File.dirname(__FILE__)}/local-space")
Conspire.discover
end

def teardown
FileUtils.rm_rf(REMOTE_SPACE)
FileUtils.rm_rf(LOCAL_SPACE)
@remote_thread.kill
Conspire.reset!
end

def test_start
assert_equal ['localhost:7458'], Conspire.conspirators.map{ |s| s.to_s }
end

def test_subscribe
assert_equal ['file'], Conspire.files.map{ |f| f.name }
end

def test_commit
end

def test_rebase
end
end

0 comments on commit 9b7ec9e

Please sign in to comment.