Commit 15c7966b authored by Fabio Pelosin's avatar Fabio Pelosin

[Command::Repo::Push] Use URL to check wether it is master repo

https://github.com/CocoaPods/CocoaPods/pull/2153#issuecomment-43617235
parent 57faf4f4
...@@ -35,12 +35,10 @@ module Pod ...@@ -35,12 +35,10 @@ module Pod
def validate! def validate!
super super
help! "A spec-repo name is required." unless @repo help! "A spec-repo name is required." unless @repo
if @repo == 'master'
help! "To push to the master repo use the `pod trunk push` command"
end
end end
def run def run
check_if_master_repo
validate_podspec_files validate_podspec_files
check_repo_status check_repo_status
update_repo update_repo
...@@ -57,6 +55,29 @@ module Pod ...@@ -57,6 +55,29 @@ module Pod
extend Executable extend Executable
executable :git executable :git
# Temporary check to ensure that users do not push accidentally private
# specs to the master repo.
#
def check_if_master_repo
remotes = Dir.chdir(repo_dir) { `git remote -v 2>&1` }
master_repo_urls = [
'git@github.com:CocoaPods/Specs.git',
'https://github.com/CocoaPods/Specs.git',
]
is_master_repo = master_repo_urls.any? do |url|
remotes.include?(url)
end
if is_master_repo
raise Informative, "To push to the CocoaPods master repo use " \
"the `pod trunk push` command.\n\nIf you are using a fork of " \
"the master repo for private purposes we recommend to migrate " \
"to a clean private repo. To disable this check remove the " \
"remote pointing to the CocoaPods master repo."
end
end
# Performs a full lint against the podspecs. # Performs a full lint against the podspecs.
# #
def validate_podspec_files def validate_podspec_files
......
...@@ -12,6 +12,7 @@ module Pod ...@@ -12,6 +12,7 @@ module Pod
it "complains if it can't find the repo" do it "complains if it can't find the repo" do
Dir.chdir(fixture('banana-lib')) do Dir.chdir(fixture('banana-lib')) do
cmd = command('repo', 'push', 'missing_repo') cmd = command('repo', 'push', 'missing_repo')
cmd.expects(:check_if_master_repo)
cmd.expects(:validate_podspec_files).returns(true) cmd.expects(:validate_podspec_files).returns(true)
e = lambda { cmd.run }.should.raise Informative e = lambda { cmd.run }.should.raise Informative
e.message.should.match(/repo not found/) e.message.should.match(/repo not found/)
...@@ -64,6 +65,15 @@ module Pod ...@@ -64,6 +65,15 @@ module Pod
File.open(temporary_directory + 'BananaLib.podspec', 'w') {|f| f.write(spec_clean) } File.open(temporary_directory + 'BananaLib.podspec', 'w') {|f| f.write(spec_clean) }
end end
it "refuses to push if the repo is not clean" do
Dir.chdir(test_repo_path) do
`git remote set-url origin https://github.com/CocoaPods/Specs.git`
end
cmd = command('repo', 'push', 'master')
e = lambda { cmd.run }.should.raise Pod::Informative
e.message.should.match(/use the `pod trunk push` command/)
end
it "refuses to push if the repo is not clean" do it "refuses to push if the repo is not clean" do
Dir.chdir(test_repo_path) do Dir.chdir(test_repo_path) do
`touch DIRTY_FILE` `touch DIRTY_FILE`
......
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