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

Implement `repo add`.

parent 7ce508b5
...@@ -17,10 +17,11 @@ module Pod ...@@ -17,10 +17,11 @@ module Pod
end end
def initialize(*argv) def initialize(*argv)
raise "unknown argument(s): #{argv.join(', ')}" unless argv.empty? raise ArgumentError, "unknown argument(s): #{argv.join(', ')}" unless argv.empty?
end end
def run def repos_dir
File.expand_path('~/.cocoa-pods')
end end
end end
end end
require 'executioner'
require 'fileutils'
module Pod module Pod
class Command class Command
class Repo < 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 end
end end
......
require 'fileutils' require 'cocoa_pods/command/repo'
require 'executioner'
module Pod module Pod
class Command class Command
class Setup < 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 def master_repo_url
'git://github.com/alloy/cocoa-pod-specs.git' 'git://github.com/alloy/cocoa-pod-specs.git'
end end
def add_master_repo_command
@command ||= Repo.new('add', 'master', master_repo_url)
end
def run def run
FileUtils.mkdir_p(repos_dir) add_master_repo_command.run
Dir.chdir(repos_dir) { git("clone #{master_repo_url} master") }
end end
end end
end end
......
...@@ -8,14 +8,19 @@ describe "Pod::Command" do ...@@ -8,14 +8,19 @@ describe "Pod::Command" do
extend SpecHelper::TemporaryDirectory extend SpecHelper::TemporaryDirectory
it "creates the local spec-repos directory and creates a clone of the `master' repo" do 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.repos_dir; SpecHelper.tmp_repos_path; end
def command.master_repo_url; SpecHelper.fixture('master-spec-repo.git'); end
command.run command.run
File.should.exist command.master_repo_dir git_config('private', 'remote.origin.url').should == fixture('master-spec-repo.git')
git_config('remote.origin.url').should == command.master_repo_url
end end
end end
...@@ -20,12 +20,12 @@ module SpecHelper ...@@ -20,12 +20,12 @@ module SpecHelper
executable :git executable :git
alias_method :git_super, :git alias_method :git_super, :git
def git(command) def git(repo, command)
Dir.chdir(tmp_master_repo_path) { git_super(command).strip } Dir.chdir(File.join(tmp_repos_path, repo)) { git_super(command).strip }
end end
def git_config(attr) def git_config(repo, attr)
git "config --get #{attr}" git repo, "config --get #{attr}"
end end
end end
end end
...@@ -11,7 +11,7 @@ end ...@@ -11,7 +11,7 @@ end
describe "Pod::Command::Setup" do describe "Pod::Command::Setup" do
it "complains about unknown arguments" 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 end
before do before do
...@@ -25,8 +25,15 @@ describe "Pod::Command::Setup" 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 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") @command.repos_dir.should == File.expand_path("~/.cocoa-pods")
end 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 it "returns the path of the spec-repo directory" do
@command.master_repo_dir.should == File.expand_path("~/.cocoa-pods/master") repo = Pod::Command::Repo.new('cd', 'private')
repo.dir.should == File.expand_path("~/.cocoa-pods/private")
end end
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