Skip to content

Commit

Permalink
Merge pull request #10194 from gyfelton/update_source_feature_for_pod…
Browse files Browse the repository at this point in the history
…_publish-v2

Add a new option for updating sources before a podspec push action
  • Loading branch information
amorde committed Nov 12, 2020
2 parents 7788e71 + 2751785 commit f0ca355
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`

##### Enhancements

* Add a `--update-sources` option to `pod repo push` so one can ensure sources are up-to-date.
[Elton Gao](https://github.com/gyfelton)
[Justin Martin](https://github.com/justinseanmartin)

* Installing a local (`:path`) pod that defines script phases will no longer
produce warnings.
[Samuel Giddins](https://github.com/segiddins)
Expand Down
17 changes: 17 additions & 0 deletions lib/cocoapods/command/repo/push.rb
Expand Up @@ -37,6 +37,7 @@ def self.options
['--swift-version=VERSION', 'The `SWIFT_VERSION` that should be used when linting the spec. ' \
'This takes precedence over the Swift versions specified by the spec or a `.swift-version` file'],
['--no-overwrite', 'Disallow pushing that would overwrite an existing spec'],
['--update-sources', 'Make sure sources are up-to-date before a push'],
].concat(super)
end

Expand All @@ -46,6 +47,7 @@ def initialize(argv)
@repo = argv.shift_argument
@source = source_for_repo
@source_urls = argv.option('sources', config.sources_manager.all.map(&:url).append(Pod::TrunkSource::TRUNK_REPO_URL).uniq.join(',')).split(',')
@update_sources = argv.flag?('update-sources')
@podspec = argv.shift_argument
@use_frameworks = !argv.flag?('use-libraries')
@use_modular_headers = argv.flag?('use-modular-headers', false)
Expand Down Expand Up @@ -73,6 +75,7 @@ def validate!
def run
open_editor if @commit_message && @message.nil?
check_if_push_allowed
update_sources if @update_sources
validate_podspec_files
check_repo_status
update_repo
Expand Down Expand Up @@ -177,6 +180,20 @@ def update_repo
git!(%W(-C #{repo_dir} pull))
end

# Update sources if present
#
# @return [void]
#
def update_sources
return if @source_urls.nil?
@source_urls.each do |source_url|
source = config.sources_manager.source_with_name_or_url(source_url)
dir = source.specs_dir
UI.puts "Updating a source at #{dir} for #{source}"
git!(%W(-C #{dir} pull))
end
end

# Commits the podspecs to the source, which should be a git repo.
#
# @note The pre commit hook of the repo is skipped as the podspecs have
Expand Down
10 changes: 10 additions & 0 deletions spec/functional/command/repo/push_spec.rb
Expand Up @@ -178,6 +178,16 @@ module Pod
(@upstream + 'PushTest/1.4/PushTest.podspec.json').read.should.include('PushTest')
end

it 'successfully pushes a spec with flag update-sources' do
cmd = command('repo', 'push', 'master', '--update-sources')
Dir.chdir(@upstream) { `git checkout -b tmp_for_push -q` }
cmd.expects(:validate_podspec_files).returns(true)
cmd.expects(:update_sources)
Dir.chdir(temporary_directory) { cmd.run }
Dir.chdir(@upstream) { `git checkout main -q` }
cmd.instance_variable_get(:@update_sources).should.equal true
end

it 'initializes with default sources if no custom sources specified' do
cmd = command('repo', 'push', 'master')
cmd.instance_variable_get(:@source_urls).should.equal [@upstream.to_s, Pod::TrunkSource::TRUNK_REPO_URL]
Expand Down

0 comments on commit f0ca355

Please sign in to comment.