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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
|
# frozen_string_literal: true
RSpec.describe "bundle update" do
describe "git sources" do
it "floats on a branch when :branch is used" do
build_git "foo", "1.0"
update_git "foo", branch: "omg"
install_gemfile <<-G
source "https://gem.repo1"
git "#{lib_path("foo-1.0")}", :branch => "omg" do
gem 'foo'
end
G
update_git "foo" do |s|
s.write "lib/foo.rb", "FOO = '1.1'"
end
bundle "update", all: true
expect(the_bundle).to include_gems "foo 1.1"
end
it "updates correctly when you have like craziness" do
build_lib "activesupport", "3.0", path: lib_path("rails/activesupport")
build_git "rails", "3.0", path: lib_path("rails") do |s|
s.add_dependency "activesupport", "= 3.0"
end
install_gemfile <<-G
source "https://gem.repo1"
gem "rails", :git => "#{lib_path("rails")}"
G
bundle "update rails"
expect(the_bundle).to include_gems "rails 3.0", "activesupport 3.0"
end
it "floats on a branch when :branch is used and the source is specified in the update" do
build_git "foo", "1.0", path: lib_path("foo")
update_git "foo", branch: "omg", path: lib_path("foo")
install_gemfile <<-G
source "https://gem.repo1"
git "#{lib_path("foo")}", :branch => "omg" do
gem 'foo'
end
G
update_git "foo", path: lib_path("foo") do |s|
s.write "lib/foo.rb", "FOO = '1.1'"
end
bundle "update --source foo"
expect(the_bundle).to include_gems "foo 1.1"
end
it "floats on main when updating all gems that are pinned to the source even if you have child dependencies" do
build_git "foo", path: lib_path("foo")
build_gem "bar", to_bundle: true do |s|
s.add_dependency "foo"
end
install_gemfile <<-G
source "https://gem.repo1"
gem "foo", :git => "#{lib_path("foo")}"
gem "bar"
G
update_git "foo", path: lib_path("foo") do |s|
s.write "lib/foo.rb", "FOO = '1.1'"
end
bundle "update foo"
expect(the_bundle).to include_gems "foo 1.1"
end
it "notices when you change the repo url in the Gemfile" do
build_git "foo", path: lib_path("foo_one")
build_git "foo", path: lib_path("foo_two")
install_gemfile <<-G
source "https://gem.repo1"
gem "foo", "1.0", :git => "#{lib_path("foo_one")}"
G
FileUtils.rm_r lib_path("foo_one")
install_gemfile <<-G
source "https://gem.repo1"
gem "foo", "1.0", :git => "#{lib_path("foo_two")}"
G
expect(err).to be_empty
expect(out).to include("Fetching #{lib_path}/foo_two")
expect(out).to include("Bundle complete!")
end
it "fetches tags from the remote" do
build_git "foo"
@remote = build_git("bar", bare: true)
update_git "foo", remote: @remote.path
update_git "foo", push: "main"
install_gemfile <<-G
source "https://gem.repo1"
gem 'foo', :git => "#{@remote.path}"
G
# Create a new tag on the remote that needs fetching
update_git "foo", tag: "fubar"
update_git "foo", push: "fubar"
gemfile <<-G
source "https://gem.repo1"
gem 'foo', :git => "#{@remote.path}", :tag => "fubar"
G
bundle "update", all: true
expect(err).to be_empty
end
describe "with submodules" do
before :each do
# CVE-2022-39253: https://lore.kernel.org/lkml/xmqq4jw1uku5.fsf@gitster.g/
system(*%W[git config --global protocol.file.allow always])
build_repo4 do
build_gem "submodule" do |s|
s.write "lib/submodule.rb", "puts 'GEM'"
end
end
build_git "submodule", "1.0" do |s|
s.write "lib/submodule.rb", "puts 'GIT'"
end
build_git "has_submodule", "1.0" do |s|
s.add_dependency "submodule"
end
git "submodule add #{lib_path("submodule-1.0")} submodule-1.0", lib_path("has_submodule-1.0")
git "commit -m \"submodulator\"", lib_path("has_submodule-1.0")
end
it "it unlocks the source when submodules are added to a git source" do
install_gemfile <<-G
source "https://gem.repo4"
git "#{lib_path("has_submodule-1.0")}" do
gem "has_submodule"
end
G
run "require 'submodule'"
expect(out).to eq("GEM")
install_gemfile <<-G
source "https://gem.repo4"
git "#{lib_path("has_submodule-1.0")}", :submodules => true do
gem "has_submodule"
end
G
run "require 'submodule'"
expect(out).to eq("GIT")
end
it "unlocks the source when submodules are removed from git source", git: ">= 2.9.0" do
install_gemfile <<-G
source "https://gem.repo4"
git "#{lib_path("has_submodule-1.0")}", :submodules => true do
gem "has_submodule"
end
G
run "require 'submodule'"
expect(out).to eq("GIT")
install_gemfile <<-G
source "https://gem.repo4"
git "#{lib_path("has_submodule-1.0")}" do
gem "has_submodule"
end
G
run "require 'submodule'"
expect(out).to eq("GEM")
end
end
it "errors with a message when the .git repo is gone" do
build_git "foo", "1.0"
install_gemfile <<-G
source "https://gem.repo1"
gem "foo", :git => "#{lib_path("foo-1.0")}"
G
lib_path("foo-1.0").join(".git").rmtree
bundle :update, all: true, raise_on_error: false
expect(err).to include(lib_path("foo-1.0").to_s).
and match(/Git error: command `git fetch.+has failed/)
end
it "should not explode on invalid revision on update of gem by name" do
build_git "myrack", "0.8"
build_git "myrack", "0.8", path: lib_path("local-myrack") do |s|
s.write "lib/myrack.rb", "puts :LOCAL"
end
install_gemfile <<-G
source "https://gem.repo1"
gem "myrack", :git => "#{lib_path("myrack-0.8")}", :branch => "main"
G
bundle %(config set local.myrack #{lib_path("local-myrack")})
bundle "update myrack"
expect(out).to include("Bundle updated!")
end
it "shows the previous version of the gem" do
build_git "rails", "2.3.2", path: lib_path("rails")
install_gemfile <<-G
source "https://gem.repo1"
gem "rails", :git => "#{lib_path("rails")}"
G
update_git "rails", "3.0", path: lib_path("rails"), gemspec: true
bundle "update", all: true
expect(out).to include("Using rails 3.0 (was 2.3.2) from #{lib_path("rails")} (at main@#{revision_for(lib_path("rails"))[0..6]})")
end
end
describe "with --source flag" do
before :each do
build_repo2
@git = build_git "foo", path: lib_path("foo") do |s|
s.executables = "foobar"
end
install_gemfile <<-G
source "https://gem.repo2"
git "#{lib_path("foo")}" do
gem 'foo'
end
gem 'myrack'
G
end
it "updates the source" do
update_git "foo", path: @git.path
bundle "update --source foo"
run <<-RUBY
require 'foo'
puts "WIN" if defined?(FOO_PREV_REF)
RUBY
expect(out).to eq("WIN")
end
it "unlocks gems that were originally pulled in by the source" do
update_git "foo", "2.0", path: @git.path
bundle "update --source foo"
expect(the_bundle).to include_gems "foo 2.0"
end
it "leaves all other gems frozen" do
update_repo2
update_git "foo", path: @git.path
bundle "update --source foo"
expect(the_bundle).to include_gems "myrack 1.0"
end
end
context "when the gem and the repository have different names" do
before :each do
build_repo2
@git = build_git "foo", path: lib_path("bar")
install_gemfile <<-G
source "https://gem.repo2"
git "#{lib_path("bar")}" do
gem 'foo'
end
gem 'myrack'
G
end
it "the --source flag updates version of gems that were originally pulled in by the source" do
spec_lines = lib_path("bar/foo.gemspec").read.split("\n")
spec_lines[5] = "s.version = '2.0'"
update_git "foo", "2.0", path: @git.path do |s|
s.write "foo.gemspec", spec_lines.join("\n")
end
ref = @git.ref_for "main"
bundle "update --source bar"
checksums = checksums_section_when_enabled do |c|
c.no_checksum "foo", "2.0"
c.checksum gem_repo2, "myrack", "1.0.0"
end
expect(lockfile).to eq <<~G
GIT
remote: #{@git.path}
revision: #{ref}
specs:
foo (2.0)
GEM
remote: https://gem.repo2/
specs:
myrack (1.0.0)
PLATFORMS
#{lockfile_platforms}
DEPENDENCIES
foo!
myrack
#{checksums}
BUNDLED WITH
#{Bundler::VERSION}
G
end
end
end
|