Commit 2e909ac2 authored by Eloy Duran's avatar Eloy Duran

Implement `repo add`.

parent 7ce508b5
......@@ -17,10 +17,11 @@ module Pod
end
def initialize(*argv)
raise "unknown argument(s): #{argv.join(', ')}" unless argv.empty?
raise ArgumentError, "unknown argument(s): #{argv.join(', ')}" unless argv.empty?
end
def run
def repos_dir
File.expand_path('~/.cocoa-pods')
end
end
end
require 'executioner'
require 'fileutils'
module Pod
class Command
class Repo < Command
include Executioner
executable :git
def initialize(*argv)
case @action = argv[0]
when'add'
unless (@name = argv[1]) && (@url = argv[2])
raise ArgumentError, "needs a NAME and URL"
end
when 'cd'
unless @name = argv[1]
raise ArgumentError, "needs a NAME"
end
else
super
end
end
def dir
File.join(repos_dir, @name)
end
def run
send @action
end
def add
FileUtils.mkdir_p(repos_dir)
Dir.chdir(repos_dir) { git("clone #{@url} #{@name}") }
end
end
end
end
......
require 'fileutils'
require 'executioner'
require 'cocoa_pods/command/repo'
module Pod
class Command
class Setup < Command
include Executioner
executable :git
def repos_dir
File.expand_path('~/.cocoa-pods')
end
def master_repo_dir
File.join(repos_dir, 'master')
end
def master_repo_url
'git://github.com/alloy/cocoa-pod-specs.git'
end
def add_master_repo_command
@command ||= Repo.new('add', 'master', master_repo_url)
end
def run
FileUtils.mkdir_p(repos_dir)
Dir.chdir(repos_dir) { git("clone #{master_repo_url} master") }
add_master_repo_command.run
end
end
end
......
......@@ -8,14 +8,19 @@ describe "Pod::Command" do
extend SpecHelper::TemporaryDirectory
it "creates the local spec-repos directory and creates a clone of the `master' repo" do
#log!
command = Pod::Command.parse('setup')
def command.master_repo_url; SpecHelper.fixture('master-spec-repo.git'); end
def (command.add_master_repo_command).repos_dir; SpecHelper.tmp_repos_path; end
command = Pod::Command.parse("setup")
command.run
git_config('master', 'remote.origin.url').should == fixture('master-spec-repo.git')
end
it "adds a spec-repo" do
command = Pod::Command.parse('repo', 'add', 'private', fixture('master-spec-repo.git'))
def command.repos_dir; SpecHelper.tmp_repos_path; end
def command.master_repo_url; SpecHelper.fixture('master-spec-repo.git'); end
command.run
File.should.exist command.master_repo_dir
git_config('remote.origin.url').should == command.master_repo_url
git_config('private', 'remote.origin.url').should == fixture('master-spec-repo.git')
end
end
......@@ -20,12 +20,12 @@ module SpecHelper
executable :git
alias_method :git_super, :git
def git(command)
Dir.chdir(tmp_master_repo_path) { git_super(command).strip }
def git(repo, command)
Dir.chdir(File.join(tmp_repos_path, repo)) { git_super(command).strip }
end
def git_config(attr)
git "config --get #{attr}"
def git_config(repo, attr)
git repo, "config --get #{attr}"
end
end
end
......@@ -11,7 +11,7 @@ end
describe "Pod::Command::Setup" do
it "complains about unknown arguments" do
lambda { Pod::Command::Setup.new('something') }.should.raise
lambda { Pod::Command::Setup.new('something') }.should.raise ArgumentError
end
before do
......@@ -25,8 +25,15 @@ describe "Pod::Command::Setup" do
it "returns the path of the directory where the local spec-repos will be stored" do
@command.repos_dir.should == File.expand_path("~/.cocoa-pods")
end
end
describe "Pod::Command::Repo" do
it "complains about unknown arguments" do
lambda { Pod::Command::Repo.new('something') }.should.raise ArgumentError
end
it "returns the path of the directory where the `master' spec-repo will be" do
@command.master_repo_dir.should == File.expand_path("~/.cocoa-pods/master")
it "returns the path of the spec-repo directory" do
repo = Pod::Command::Repo.new('cd', 'private')
repo.dir.should == File.expand_path("~/.cocoa-pods/private")
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment