@@ -10,6 +10,8 @@ def self.bundler_version
1010 v ||= bundle_update_bundler_version
1111 return if v == true
1212
13+ v ||= bundle_config_version
14+
1315 v ||= lockfile_version
1416 return unless v
1517
@@ -49,21 +51,7 @@ def self.lockfile_version
4951 private_class_method :lockfile_version
5052
5153 def self . lockfile_contents
52- gemfile = ENV [ "BUNDLE_GEMFILE" ]
53- gemfile = nil if gemfile &.empty?
54-
55- unless gemfile
56- begin
57- Gem ::Util . traverse_parents ( Dir . pwd ) do |directory |
58- next unless gemfile = Gem ::GEM_DEP_FILES . find { |f | File . file? ( f ) }
59-
60- gemfile = File . join directory , gemfile
61- break
62- end
63- rescue Errno ::ENOENT
64- return
65- end
66- end
54+ gemfile = gemfile_path
6755
6856 return unless gemfile
6957
@@ -82,19 +70,24 @@ def self.lockfile_contents
8270 private_class_method :lockfile_contents
8371
8472 def self . bundle_config_version
85- config_file = bundler_config_file
86- return unless config_file && File . file? ( config_file )
73+ version = nil
8774
88- contents = File . read ( config_file )
89- contents =~ /^BUNDLE_VERSION: \s *["']?([^"' \s ]+)["']? \s *$/
75+ [ bundler_local_config_file , bundler_global_config_file ] . each do | config_file |
76+ next unless config_file && File . file? ( config_file )
9077
91- $1
78+ contents = File . read ( config_file )
79+ contents =~ /^BUNDLE_VERSION:\s *["']?([^"'\s ]+)["']?\s *$/
80+
81+ version = $1
82+ break if version
83+ end
84+
85+ version
9286 end
9387 private_class_method :bundle_config_version
9488
95- def self . bundler_config_file
96- # see Bundler::Settings#global_config_file and local_config_file
97- # global
89+ def self . bundler_global_config_file
90+ # see Bundler::Settings#global_config_file
9891 if ENV [ "BUNDLE_CONFIG" ] && !ENV [ "BUNDLE_CONFIG" ] . empty?
9992 ENV [ "BUNDLE_CONFIG" ]
10093 elsif ENV [ "BUNDLE_USER_CONFIG" ] && !ENV [ "BUNDLE_USER_CONFIG" ] . empty?
@@ -103,10 +96,36 @@ def self.bundler_config_file
10396 ENV [ "BUNDLE_USER_HOME" ] + "config"
10497 elsif Gem . user_home && !Gem . user_home . empty?
10598 Gem . user_home + ".bundle/config"
106- else
107- # local
108- "config"
10999 end
110100 end
111- private_class_method :bundler_config_file
101+ private_class_method :bundler_global_config_file
102+
103+ def self . bundler_local_config_file
104+ gemfile = gemfile_path
105+ return unless gemfile
106+
107+ File . join ( File . dirname ( gemfile ) , ".bundle" , "config" )
108+ end
109+ private_class_method :bundler_local_config_file
110+
111+ def self . gemfile_path
112+ gemfile = ENV [ "BUNDLE_GEMFILE" ]
113+ gemfile = nil if gemfile &.empty?
114+
115+ unless gemfile
116+ begin
117+ Gem ::Util . traverse_parents ( Dir . pwd ) do |directory |
118+ next unless gemfile = Gem ::GEM_DEP_FILES . find { |f | File . file? ( f ) }
119+
120+ gemfile = File . join directory , gemfile
121+ break
122+ end
123+ rescue Errno ::ENOENT
124+ return
125+ end
126+ end
127+
128+ gemfile
129+ end
130+ private_class_method :gemfile_path
112131end
0 commit comments