Skip to content

Commit 3802477

Browse files
deivid-rodriguezhsbt
authored andcommitted
[rubygems/rubygems] Refine bundle update --verbose logs
Don't mention "Found changes from the lockfile" because that's not really true in general. ruby/rubygems@0181c278e8
1 parent ce2640d commit 3802477

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

lib/bundler/definition.rb

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,7 @@ def resolve
337337
end
338338
end
339339
else
340-
if lockfile_exists?
341-
Bundler.ui.debug "Found changes from the lockfile, re-resolving dependencies because #{change_reason}"
342-
else
343-
Bundler.ui.debug "Resolving dependencies because there's no lockfile"
344-
end
340+
Bundler.ui.debug resolve_needed_reason
345341

346342
start_resolution
347343
end
@@ -537,9 +533,7 @@ def lockfile_changes_summary(update_refused_reason)
537533

538534
return unless added.any? || deleted.any? || changed.any? || resolve_needed?
539535

540-
reason = resolve_needed? ? change_reason : "some dependencies were deleted from your gemfile"
541-
542-
msg = String.new("#{reason.capitalize.strip}, but ")
536+
msg = String.new("#{change_reason.capitalize.strip}, but ")
543537
msg << "the lockfile " unless msg.start_with?("Your lockfile")
544538
msg << "can't be updated because #{update_refused_reason}"
545539
msg << "\n\nYou have added to the Gemfile:\n" << added.join("\n") if added.any?
@@ -796,22 +790,47 @@ def find_most_specific_locked_platform
796790
@most_specific_locked_platform
797791
end
798792

799-
def change_reason
800-
if unlocking?
801-
unlock_targets = if @gems_to_unlock.any?
802-
["gems", @gems_to_unlock]
803-
elsif @sources_to_unlock.any?
804-
["sources", @sources_to_unlock]
793+
def resolve_needed_reason
794+
if lockfile_exists?
795+
if unlocking?
796+
"Re-resolving dependencies because #{unlocking_reason}"
797+
else
798+
"Found changes from the lockfile, re-resolving dependencies because #{lockfile_changed_reason}"
805799
end
800+
else
801+
"Resolving dependencies because there's no lockfile"
802+
end
803+
end
806804

807-
unlock_reason = if unlock_targets
808-
"#{unlock_targets.first}: (#{unlock_targets.last.join(", ")})"
805+
def change_reason
806+
if resolve_needed?
807+
if unlocking?
808+
unlocking_reason
809809
else
810-
@unlocking_ruby ? "ruby" : ""
810+
lockfile_changed_reason
811811
end
812+
else
813+
"some dependencies were deleted from your gemfile"
814+
end
815+
end
812816

813-
return "bundler is unlocking #{unlock_reason}"
817+
def unlocking_reason
818+
unlock_targets = if @gems_to_unlock.any?
819+
["gems", @gems_to_unlock]
820+
elsif @sources_to_unlock.any?
821+
["sources", @sources_to_unlock]
814822
end
823+
824+
unlock_reason = if unlock_targets
825+
"#{unlock_targets.first}: (#{unlock_targets.last.join(", ")})"
826+
else
827+
@unlocking_ruby ? "ruby" : ""
828+
end
829+
830+
"bundler is unlocking #{unlock_reason}"
831+
end
832+
833+
def lockfile_changed_reason
815834
[
816835
[@source_changes, "the list of sources changed"],
817836
[@dependency_changes, "the dependencies in your gemfile changed"],

spec/bundler/commands/update_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@
3939
end
4040
end
4141

42+
describe "with --verbose" do
43+
before do
44+
build_repo2
45+
46+
install_gemfile <<~G
47+
source "https://gem.repo2"
48+
gem "myrack"
49+
G
50+
end
51+
52+
it "logs the reason for re-resolving" do
53+
bundle "update --verbose"
54+
expect(out).not_to include("Found changes from the lockfile")
55+
expect(out).to include("Re-resolving dependencies because bundler is unlocking")
56+
end
57+
end
58+
4259
describe "with --all" do
4360
before do
4461
build_repo2

0 commit comments

Comments
 (0)