Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix fetching a specific prerelease version

  • Loading branch information...
commit 38a4bbfffdda762531ba33ee9390d949627dc100 1 parent e0db4ce
@evanphx evanphx authored lsegal committed
View
24 lib/rubygems/commands/fetch_command.rb
@@ -36,18 +36,32 @@ def execute
version = options[:version] || Gem::Requirement.default
all = Gem::Requirement.default != version
+ platform = Gem.platforms.last
gem_names = get_all_gem_names
gem_names.each do |gem_name|
dep = Gem::Dependency.new gem_name, version
dep.prerelease = options[:prerelease]
- specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, all, true,
- dep.prerelease?)
+ # Because of the madness that is SpecFetcher, you can't
+ # set both all and prerelease to true. If you do, prerelease
+ # is ignored.
+
+ if dep.prerelease? and all
+ specs_and_sources, errors =
+ Gem::SpecFetcher.fetcher.fetch_with_errors(dep, false, true,
+ dep.prerelease?)
+ else
+ specs_and_sources, errors =
+ Gem::SpecFetcher.fetcher.fetch_with_errors(dep, all, true,
+ dep.prerelease?)
+ end
+
- specs_and_sources, errors =
- Gem::SpecFetcher.fetcher.fetch_with_errors(dep, all, true,
- dep.prerelease?)
+ if platform then
+ filtered = specs_and_sources.select { |s,| s.platform == platform }
+ specs_and_sources = filtered unless filtered.empty?
+ end
spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last
View
24 test/test_gem_commands_fetch_command.rb
@@ -52,6 +52,30 @@ def test_execute_prerelease
"#{@a2_pre.full_name} not fetched"
end
+ def test_execute_specific_prerelease
+ util_setup_fake_fetcher true
+ util_clear_gems
+ util_setup_spec_fetcher @a2, @a2_pre
+
+ @fetcher.data["#{@gem_repo}gems/#{@a2.file_name}"] =
+ File.read(File.join(@gemhome, 'cache', @a2.file_name))
+ @fetcher.data["#{@gem_repo}gems/#{@a2_pre.file_name}"] =
+ File.read(File.join(@gemhome, 'cache', @a2_pre.file_name))
+
+ @cmd.options[:args] = [@a2.name]
+ @cmd.options[:prerelease] = true
+ @cmd.options[:version] = "2.a"
+
+ use_ui @ui do
+ Dir.chdir @tempdir do
+ @cmd.execute
+ end
+ end
+
+ assert File.exist?(File.join(@tempdir, @a2_pre.file_name)),
+ "#{@a2_pre.full_name} not fetched"
+ end
+
def test_execute_version
util_setup_fake_fetcher
util_setup_spec_fetcher @a1, @a2
Please sign in to comment.
Something went wrong with that request. Please try again.