@@ -412,39 +412,8 @@ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
412412
413413 raise ProductionError , "Frozen mode is set, but there's no lockfile" unless lockfile_exists?
414414
415- added = [ ]
416- deleted = [ ]
417- changed = [ ]
418-
419- added . concat @new_platforms . map { |p | "* platform: #{ p } " }
420- deleted . concat @removed_platforms . map { |p | "* platform: #{ p } " }
421-
422- added . concat new_deps . map { |d | "* #{ pretty_dep ( d ) } " } if new_deps . any?
423- deleted . concat deleted_deps . map { |d | "* #{ pretty_dep ( d ) } " } if deleted_deps . any?
424-
425- both_sources = Hash . new { |h , k | h [ k ] = [ ] }
426- current_dependencies . each { |d | both_sources [ d . name ] [ 0 ] = d }
427- current_locked_dependencies . each { |d | both_sources [ d . name ] [ 1 ] = d }
428-
429- both_sources . each do |name , ( dep , lock_dep ) |
430- next if dep . nil? || lock_dep . nil?
431-
432- gemfile_source = dep . source || default_source
433- lock_source = lock_dep . source || default_source
434- next if lock_source . include? ( gemfile_source )
435-
436- gemfile_source_name = dep . source ? gemfile_source . to_gemfile : "no specified source"
437- lockfile_source_name = lock_dep . source ? lock_source . to_gemfile : "no specified source"
438- changed << "* #{ name } from `#{ lockfile_source_name } ` to `#{ gemfile_source_name } `"
439- end
440-
441- reason = resolve_needed? ? change_reason : "some dependencies were deleted from your gemfile"
442- msg = String . new
443- msg << "#{ reason . capitalize . strip } , but the lockfile can't be updated because frozen mode is set"
444- msg << "\n \n You have added to the Gemfile:\n " << added . join ( "\n " ) if added . any?
445- msg << "\n \n You have deleted from the Gemfile:\n " << deleted . join ( "\n " ) if deleted . any?
446- msg << "\n \n You have changed in the Gemfile:\n " << changed . join ( "\n " ) if changed . any?
447- msg << "\n \n Run `bundle install` elsewhere and add the updated #{ SharedHelpers . relative_gemfile_path } to version control.\n " unless unlocking?
415+ msg = lockfile_changes_summary ( "frozen mode is set" )
416+ return unless msg
448417
449418 unless explicit_flag
450419 suggested_command = unless Bundler . settings . locations ( "frozen" ) . keys . include? ( :env )
@@ -454,7 +423,7 @@ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
454423 "freeze by running `#{ suggested_command } `." if suggested_command
455424 end
456425
457- raise ProductionError , msg if added . any? || deleted . any? || changed . any? || resolve_needed?
426+ raise ProductionError , msg
458427 end
459428
460429 def validate_runtime!
@@ -539,6 +508,46 @@ def add_checksums
539508
540509 private
541510
511+ def lockfile_changes_summary ( update_refused_reason )
512+ added = [ ]
513+ deleted = [ ]
514+ changed = [ ]
515+
516+ added . concat @new_platforms . map { |p | "* platform: #{ p } " }
517+ deleted . concat @removed_platforms . map { |p | "* platform: #{ p } " }
518+
519+ added . concat new_deps . map { |d | "* #{ pretty_dep ( d ) } " } if new_deps . any?
520+ deleted . concat deleted_deps . map { |d | "* #{ pretty_dep ( d ) } " } if deleted_deps . any?
521+
522+ both_sources = Hash . new { |h , k | h [ k ] = [ ] }
523+ current_dependencies . each { |d | both_sources [ d . name ] [ 0 ] = d }
524+ current_locked_dependencies . each { |d | both_sources [ d . name ] [ 1 ] = d }
525+
526+ both_sources . each do |name , ( dep , lock_dep ) |
527+ next if dep . nil? || lock_dep . nil?
528+
529+ gemfile_source = dep . source || default_source
530+ lock_source = lock_dep . source || default_source
531+ next if lock_source . include? ( gemfile_source )
532+
533+ gemfile_source_name = dep . source ? gemfile_source . to_gemfile : "no specified source"
534+ lockfile_source_name = lock_dep . source ? lock_source . to_gemfile : "no specified source"
535+ changed << "* #{ name } from `#{ lockfile_source_name } ` to `#{ gemfile_source_name } `"
536+ end
537+
538+ return unless added . any? || deleted . any? || changed . any? || resolve_needed?
539+
540+ reason = resolve_needed? ? change_reason : "some dependencies were deleted from your gemfile"
541+
542+ msg = String . new
543+ msg << "#{ reason . capitalize . strip } , but the lockfile can't be updated because #{ update_refused_reason } "
544+ msg << "\n \n You have added to the Gemfile:\n " << added . join ( "\n " ) if added . any?
545+ msg << "\n \n You have deleted from the Gemfile:\n " << deleted . join ( "\n " ) if deleted . any?
546+ msg << "\n \n You have changed in the Gemfile:\n " << changed . join ( "\n " ) if changed . any?
547+ msg << "\n \n Run `bundle install` elsewhere and add the updated #{ SharedHelpers . relative_gemfile_path } to version control.\n " unless unlocking?
548+ msg
549+ end
550+
542551 def install_needed?
543552 resolve_needed? || missing_specs?
544553 end
@@ -599,8 +608,12 @@ def write_lock(file, preserve_unknown_sections)
599608 return
600609 end
601610
602- SharedHelpers . filesystem_access ( file ) do |p |
603- File . open ( p , "wb" ) { |f | f . puts ( contents ) }
611+ begin
612+ SharedHelpers . filesystem_access ( file ) do |p |
613+ File . open ( p , "wb" ) { |f | f . puts ( contents ) }
614+ end
615+ rescue ReadOnlyFileSystemError
616+ raise ProductionError , lockfile_changes_summary ( "file system is read-only" )
604617 end
605618 end
606619
0 commit comments