summaryrefslogtreecommitdiff
path: root/extra/ruby/0001-Fix-installing-gem-from-file-without-dependencies.patch
blob: 8fefb275df04f02af75c9f6fff647e4d873bd708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
From f5bbf838c8b13369a61c6756355305388df5824f Mon Sep 17 00:00:00 2001
From: Tim Moore <tmoore@incrementalism.net>
Date: Tue, 31 Dec 2013 17:39:45 +1100
Subject: [PATCH] Fix installing gem from file without dependencies.

Commit 9437ccc fixed the ability to install remote gems that was accidentally
broken by d97fba1, but in the process accidentally broke installing from local
files.

This also changes the order to check for local first, to avoid unnecessary
network requests in the case where the gem is local.

Closes #760.
---
 lib/rubygems/commands/install_command.rb           | 20 ++++++++++++--------
 test/rubygems/test_gem_commands_install_command.rb | 14 ++++++++++++++
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb
index 4485eb1..8219eef 100644
--- a/lib/rubygems/commands/install_command.rb
+++ b/lib/rubygems/commands/install_command.rb
@@ -228,7 +228,18 @@ to write the specification by hand.  For example:
   def install_gem_without_dependencies name, req # :nodoc:
     gem = nil
 
-    if remote? then
+    if local? then
+      if name =~ /\.gem$/ and File.file? name then
+        source = Gem::Source::SpecificFile.new name
+        spec = source.spec
+      else
+        source = Gem::Source::Local.new
+        spec = source.find_gem name, req
+      end
+      gem = source.download spec if spec
+    end
+
+    if remote? and not gem then
       dependency = Gem::Dependency.new name, req
       dependency.prerelease = options[:prerelease]
 
@@ -236,13 +247,6 @@ to write the specification by hand.  For example:
       gem = fetcher.download_to_cache dependency
     end
 
-    if local? and not gem then
-      source = Gem::Source::Local.new
-      spec = source.find_gem name, req
-
-      gem = source.download spec
-    end
-
     inst = Gem::Installer.new gem, options
     inst.install
 
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index 76ea6b4..a5917c0 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -560,6 +560,20 @@ ERROR:  Possible alternatives: non_existent_with_hint
     assert_equal %w[a-2], @cmd.installed_specs.map { |spec| spec.full_name }
   end
 
+  def test_install_gem_ignore_dependencies_specific_file
+    spec = quick_spec 'a', 2
+
+    util_build_gem spec
+
+    FileUtils.mv spec.cache_file, @tempdir
+
+    @cmd.options[:ignore_dependencies] = true
+
+    @cmd.install_gem File.join(@tempdir, spec.file_name), nil
+
+    assert_equal %w[a-2], @cmd.installed_specs.map { |spec| spec.full_name }
+  end
+
   def test_parses_requirement_from_gemname
     spec_fetcher do |fetcher|
       fetcher.gem 'a', 2
-- 
1.8.5.2