Commit 539dc7d8 authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #2522 from CocoaPods/repo-list

Repo list
parents acd55a06 1f793c53
......@@ -26,6 +26,12 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[Core#170](https://github.com/CocoaPods/Core/issues/170)
[#2515](https://github.com/CocoaPods/CocoaPods/issues/2515)
##### 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)
##### Bug Fixes
* Works around an Xcode issue where linting would fail even though `xcodebuild`
......@@ -47,6 +53,7 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[Ladislav Martincik](https://github.com/martincik)
[#2482](https://github.com/CocoaPods/CocoaPods/issues/2482)
## 0.34.0.rc2
##### Bug Fixes
......
......@@ -9,6 +9,7 @@ module Pod
# @todo should not show a usage banner!
#
self.summary = 'Manage spec-repositories'
self.default_subcommand = 'list'
class Add < Repo
self.summary = 'Add a spec repo.'
......@@ -185,12 +186,137 @@ module Pod
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-only", "Show the total number of repos"]].concat(super)
end
def initialize(argv)
@count_only = argv.flag?('count-only')
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
print_sources(sources) unless @count_only
print_count_of_sources(sources)
end
private
# Pretty-prints the source at the given path.
#
# @param [String,Pathname] path
# The path of the source to be printed.
#
# @return [void]
#
def print_source_at_path(path)
Dir.chdir(path) do
if SourcesManager.git_repo?(path)
remote_name = branch_remote_name(branch_name)
if remote_name
UI.puts "- Type: git (#{remote_name})"
url = 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
# Pretty-prints the given sources.
#
# @param [Array<Source>] sources
# The sources that should be printed.
#
# @return [void]
#
def print_sources(sources)
sources.each do |source|
UI.title source.name do
print_source_at_path source.data_provider.repo
end
end
UI.puts "\n"
end
# Pretty-prints the number of sources.
#
# @param [Array<Source>] sources
# The sources whose count should be printed.
#
# @return [void]
#
def print_count_of_sources(sources)
number_of_repos = sources.length
repo_string = number_of_repos != 1 ? 'repos' : 'repo'
UI.puts "#{number_of_repos} #{repo_string}".green
end
end
#-----------------------------------------------------------------------#
extend Executable
executable :git
def dir
config.repos_dir + @name
end
# Returns the branch name (i.e. master).
#
# @return [String] The name of the current branch.
#
def branch_name
`git name-rev --name-only HEAD`.strip
end
# Returns the branch remote name (i.e. origin).
#
# @param [#to_s] branch_name
# The branch name to look for the remote name.
#
# @return [String] The given branch's remote name.
#
def 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 [#to_s] remote_name
# The branch remote name to look for the url.
#
# @return [String] The URL of the given remote.
#
def url_of_git_repo(remote_name)
`git config remote.#{remote_name}.url`.strip
end
end
end
end
......@@ -120,6 +120,35 @@ module Pod
lambda { run_command('repo', 'remove', upstream) }.should.not.raise
File.directory?(test_repo_path + upstream).should.be.false?
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 'only prints a count when invoked with --count-only' do
config.repos_dir = fixture('spec-repos')
output = run_command('repo', 'list', '--count-only')
output.should.include? 'repo'
output.should.not.include? '- Type:'
end
end
end
end
......@@ -6,9 +6,10 @@ module Pod
Command.parse(%w(install )).should.be.instance_of Command::Install
Command.parse(%w(list )).should.be.instance_of Command::List
Command.parse(%w(outdated )).should.be.instance_of Command::Outdated
Command.parse(%w(repo )).should.be.instance_of Command::Repo
Command.parse(%w(repo )).should.be.instance_of Command::Repo::List
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 list )).should.be.instance_of Command::Repo::List
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(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