提交 de9bfa21 编写于 作者: C Chris Wanstrath

first commit

上级
task :default => :test
chris@airistotle.local.6231
\ No newline at end of file
#!/usr/bin/env ruby
class Hub
PRIVATE = 'git@github.com:%s/%s.git'
PUBLIC = 'git://github.com/%s/%s.git'
USER = `git config --global github.user`.chomp
REPO = `basename $(pwd)`.chomp
attr_reader :args, :after
def initialize(*args)
@args = args
end
def clone
ssh = @args.delete('-p')
@args.each_with_index do |arg, i|
if arg.scan('/').size == 1 && !arg.include?(':')
url = ssh ? PRIVATE : PUBLIC
@args[i] = url % arg.split('/')
end
end
end
def remote
if @args[1] == 'add'
if @args.delete('-g')
ssh = @args.delete('-p')
user = @args.last
url = ssh ? PRIVATE : PUBLIC
@args << url % [ user, REPO ]
end
end
end
def init
if @args.delete('-g')
url = PRIVATE % [ USER, REPO ]
@after = "git remote add origin #{url}"
end
end
def execute
if respond_to?(@args[0])
send(@args[0])
end
if @after
if system("git", *@args)
exec @after
else
exit 1
end
else
exec "git", *@args
end
end
end
if $0 == __FILE__
Hub.new(*ARGV).execute
end
require 'test/unit'
load File.dirname(__FILE__) + '/../bin/hub'
class HubTest < Test::Unit::TestCase
def hub(args)
args = args.split(' ')
hub = Hub.new(*args)
hub.send(args[0])
hub
end
def test_private_clone
h = hub("clone -p rtomayko/ron")
assert_equal 'git@github.com:rtomayko/ron.git', h.args.last
end
def test_public_clone
h = hub("clone rtomayko/ron")
assert_equal 'git://github.com/rtomayko/ron.git', h.args.last
end
def test_private_remote
h = hub("remote add -g -p rtomayko")
assert_equal 'git@github.com:rtomayko/hub.git', h.args.last
end
def test_public_remote
h = hub("remote add -g rtomayko")
assert_equal 'git://github.com/rtomayko/hub.git', h.args.last
end
def test_init
h = hub("init -g")
assert_equal 'git remote add origin git@github.com:defunkt/hub.git', h.after
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册