Commit a4affd62 authored by Luis Ascorbe's avatar Luis Ascorbe Committed by Samuel E. Giddins

Added pod repo list command

parent acd55a06
...@@ -47,6 +47,13 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides ...@@ -47,6 +47,13 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[Ladislav Martincik](https://github.com/martincik) [Ladislav Martincik](https://github.com/martincik)
[#2482](https://github.com/CocoaPods/CocoaPods/issues/2482) [#2482](https://github.com/CocoaPods/CocoaPods/issues/2482)
##### Enhancements
* Added the `pod repo list` command which lists all the repositories.
[Luis Ascorbe](https://github.com/lascorbe)
[#1455](https://github.com/CocoaPods/CocoaPods/issues/1455)
## 0.34.0.rc2 ## 0.34.0.rc2
##### Bug Fixes ##### Bug Fixes
......
...@@ -9,6 +9,7 @@ module Pod ...@@ -9,6 +9,7 @@ module Pod
# @todo should not show a usage banner! # @todo should not show a usage banner!
# #
self.summary = 'Manage spec-repositories' self.summary = 'Manage spec-repositories'
self.default_subcommand = 'list'
class Add < Repo class Add < Repo
self.summary = 'Add a spec repo.' self.summary = 'Add a spec repo.'
...@@ -185,12 +186,96 @@ module Pod ...@@ -185,12 +186,96 @@ module Pod
end end
end end
#-----------------------------------------------------------------------#
class List < Repo
self.summary = 'List repos'
self.description = <<-DESC
List the repos from the local spec-repos directory at `~/.cocoapods/repos/.`
DESC
def self.options
[["--count", "Show the total number of repos"]].concat(super)
end
def initialize(argv)
@count = argv.flag?('count')
super
end
# @output Examples:
#
# master
# - type: git (origin)
# - URL: https://github.com/CocoaPods/Specs.git
# - path: /Users/lascorbe/.cocoapods/repos/master
#
# test
# - type: local copy
# - path: /Users/lascorbe/.cocoapods/repos/test
#
def run
sources = SourcesManager.all
sources.each do |source|
path = source.data_provider.repo
UI.title source.name do
Dir.chdir(path) do
if SourcesManager.git_repo?(path)
branch_name = get_branch_name
remote_name = get_branch_remote_name(branch_name)
if remote_name
UI.puts "- Type: git (#{remote_name})"
url = get_url_of_git_repo(remote_name)
UI.puts "- URL: #{url}"
else
UI.puts "- Type: git (no remote information available)"
end
else
UI.puts "- Type: local copy"
end
UI.puts "- Path: #{path}"
end
end
end
if @count
number_of_repos = sources.length
repo_string = number_of_repos != 1 ? 'repos' : 'repo'
UI.puts "\n#{number_of_repos} #{repo_string}".green
end
end
end
extend Executable extend Executable
executable :git executable :git
def dir def dir
config.repos_dir + @name config.repos_dir + @name
end end
# Returns the branch name (i.e. master)
#
def get_branch_name
git!("name-rev --name-only HEAD").strip
end
# Returns the branch remote name (i.e. origin)
#
# @param [BranchName] branch_name
# The branch name to look for the remote name.
#
def get_branch_remote_name(branch_name)
`git config branch.#{branch_name}.remote`.strip
end
# Returns the url of the given remote name (i.e. git@github.com:CocoaPods/Specs.git)
#
# @param [RemoteName] remote_name
# The branch remote name to look for the url.
#
def get_url_of_git_repo(remote_name)
`git config remote.#{remote_name}.url`.strip
end
end end
end end
end end
...@@ -120,6 +120,34 @@ module Pod ...@@ -120,6 +120,34 @@ module Pod
lambda { run_command('repo', 'remove', upstream) }.should.not.raise lambda { run_command('repo', 'remove', upstream) }.should.not.raise
File.directory?(test_repo_path + upstream).should.be.false? File.directory?(test_repo_path + upstream).should.be.false?
end end
end
describe Command::Repo::List do
extend SpecHelper::Command
extend SpecHelper::TemporaryRepos
before do
set_up_test_repo
config.repos_dir = SpecHelper.tmp_repos_path
end
it 'lists a repository' do
lambda { run_command('repo', 'list') }.should.not.raise
end
it 'lists a repository (checking the output)' do
config.repos_dir = fixture('spec-repos')
output = run_command('repo', 'list')
output.should.include? '- Type:'
end
it 'lists a repository with count' do
config.repos_dir = fixture('spec-repos')
output = run_command('repo', 'list', '--count')
output.should.include? 'repo'
end
end end
end end
end end
...@@ -9,6 +9,7 @@ module Pod ...@@ -9,6 +9,7 @@ module Pod
Command.parse(%w(repo )).should.be.instance_of Command::Repo Command.parse(%w(repo )).should.be.instance_of Command::Repo
Command.parse(%w(repo add )).should.be.instance_of Command::Repo::Add Command.parse(%w(repo add )).should.be.instance_of Command::Repo::Add
Command.parse(%w(repo lint )).should.be.instance_of Command::Repo::Lint Command.parse(%w(repo lint )).should.be.instance_of Command::Repo::Lint
Command.parse(%w(repo list )).should.be.instance_of Command::Repo::List
Command.parse(%w(repo update )).should.be.instance_of Command::Repo::Update Command.parse(%w(repo update )).should.be.instance_of Command::Repo::Update
Command.parse(%w(repo remove )).should.be.instance_of Command::Repo::Remove Command.parse(%w(repo remove )).should.be.instance_of Command::Repo::Remove
Command.parse(%w(search )).should.be.instance_of Command::Search Command.parse(%w(search )).should.be.instance_of Command::Search
......
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