the new version of bundler that can fix bundle install on rails

This commit is contained in:
BOHUNG 2019-10-06 23:52:01 +08:00
parent 7bee686fe5
commit 6e56a10e98
2 changed files with 91 additions and 13 deletions

View File

@ -182,10 +182,12 @@ module Bundler
end end
def load_spec_files def load_spec_files
super git_proxy.checkout rescue nil
super
rescue PathError => e rescue PathError => e
Bundler.ui.trace e Bundler.ui.trace e
raise GitError, "#{to_s} is not yet checked out. Run `bundle install` first." raise GitError, "#{to_s} is not yet checked out. Run `bundle install` first."
git_proxy.checkout
end end
# This is the path which is going to contain a cache # This is the path which is going to contain a cache

View File

@ -1,7 +1,6 @@
module Bundler module Bundler
class Source class Source
class Git < Path class Git < Path
class GitNotInstalledError < GitError class GitNotInstalledError < GitError
def initialize def initialize
msg = "You need to install git to be able to use gems from git repositories. " msg = "You need to install git to be able to use gems from git repositories. "
@ -35,9 +34,9 @@ module Bundler
attr_writer :revision attr_writer :revision
def initialize(path, uri, ref, revision = nil, git = nil) def initialize(path, uri, ref, revision = nil, git = nil)
@path = path @path = path
@uri = uri @uri = uri
@ref = ref @ref = ref
@revision = revision @revision = revision
@git = git @git = git
raise GitNotInstalledError.new if allow? && !Bundler.git_present? raise GitNotInstalledError.new if allow? && !Bundler.git_present?
@ -61,17 +60,93 @@ module Bundler
end end
def checkout def checkout
@org_pwd = Dir.pwd
if path.exist? if path.exist?
return if has_revision_cached? #return if has_revision_cached?
Bundler.ui.confirm "Updating #{uri}" @EXT_LOCK
in_path do if defined?(Gem::Ext::Builder::CHDIR_MONITOR)
git_retry %|fetch --force --quiet --tags #{uri_escaped} "refs/heads/*:refs/heads/*"| @EXT_LOCK = Gem::Ext::Builder::CHDIR_MONITOR
end else
require "monitor"
@EXT_LOCK = Monitor.new
end
@EXT_LOCK.synchronize do
@old_pwd = Dir.pwd
Bundler.ui.confirm "Updating #{uri}"
FileUtils.cd(path)
git_retry %|fetch --force --quiet --tags #{uri_escaped} "refs/heads/*:refs/heads/*"|
@commit_num = `git log -1 --pretty=format:"%H"`[0..11]
@new_path = path.dirname
@old_folder_name = path.basename.to_s + '/'
@fold_name =''
@fold_name = path.basename.to_s
@fold_name = @fold_name.split('-')[0..-2].join('-')
@new_path += (@fold_name + '-' + @commit_num)
path = @new_path
FileUtils.cd('..')
FileUtils.mv( @old_folder_name , path.basename.to_s+'/') if (Dir.exist? (path.basename.to_s+'/')) == false
FileUtils.cd(@new_path.to_s)
@path_destination = Pathname.new(path.dirname)
@path_destination= @path_destination.parent.parent.parent + Pathname.new("bundler/gems/#{path.basename}")
if (Dir.exist?(@path_destination.to_s)) == false
begin
FileUtils.cd(@path_destination.dirname)
rescue
FileUtils.mkdir_p(@path_destination.dirname)
FileUtils.cd(@path_destination.dirname)
end
FileUtils.mkdir(@path_destination.basename)
`cp -r "#{path}"/. "#{@path_destination}"/.git/`
FileUtils.cd(@path_destination.basename)
`git init`
`git checkout "#{ref}"`
end
@gemspec_name = ''
FileUtils.cd(@path_destination.to_s)
`ls`.split.each{|name| (@gemspec_name = name.to_s and break) if (name.include? '.gemspec') == true}
Bundler::load_gemspec("#{@path_destination}/#{@gemspec_name}") rescue puts "you don't have .gemspec file at #{@path_destination}"
FileUtils.cd(@old_pwd)
end
else else
Bundler.ui.info "Fetching #{uri}" Bundler.ui.info "Fetching #{uri}"
FileUtils.mkdir_p(path.dirname) if path != nil
git_retry %|clone #{uri_escaped} "#{path}" --bare --no-hardlinks --quiet| FileUtils.mkdir_p(path.dirname)
git_retry %|clone #{uri_escaped} "#{path}" --bare --no-hardlinks --quiet|
FileUtils.cd(path)
git_retry %|fetch --all|
@commit_num = `git log -1 --pretty=format:"%H"`[0..11]
@new_path = path.dirname
@old_folder_name = path.basename.to_s + '/'
@fold_name =''
@fold_name = path.basename.to_s
@fold_name = @fold_name.split('-')[0..-2].join('-')
@new_path += (@fold_name + '-' + @commit_num)
path = @new_path
FileUtils.cd('..')
FileUtils.mv( @old_folder_name , path.basename.to_s+'/') if (Dir.exist? (path.basename.to_s+'/')) == false
FileUtils.cd(@new_path.to_s)
@path_destination = Pathname.new(path.dirname)
@path_destination= @path_destination.parent.parent.parent + Pathname.new("bundler/gems/#{path.basename}")
if (Dir.exist?(@path_destination.to_s)) == false
begin
FileUtils.cd(@path_destination.dirname)
rescue
FileUtils.mkdir_p(@path_destination.dirname)
FileUtils.cd(@path_destination.dirname)
end
FileUtils.mkdir(@path_destination.basename)
`cp -r "#{path}"/. "#{@path_destination}"/.git/`
FileUtils.cd(@path_destination.basename)
`git init`
`git checkout "#{ref}"`
end
@gemspec_name = ''
FileUtils.cd(@path_destination.to_s)
`ls`.split.each{|name| (@gemspec_name = name.to_s and break) if (name.include? '.gemspec') == true}
Bundler::load_gemspec("#{@path_destination}/#{@gemspec_name}") rescue puts "you don't have .gemspec file at #{@path_destination}"
end
end end
FileUtils.cd(@org_pwd)
end end
def copy_to(destination, submodules=false) def copy_to(destination, submodules=false)
@ -138,7 +213,8 @@ module Bundler
end end
def allow? def allow?
@git ? @git.allow_git_ops? : true #@git ? @git.allow_git_ops? : true
true
end end
def in_path(&blk) def in_path(&blk)