mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
a685a8643f
commit
cad71f7089
1 changed files with 22 additions and 30 deletions
|
@ -1,5 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "open3"
|
||||||
require "shellwords"
|
require "shellwords"
|
||||||
require "tempfile"
|
require "tempfile"
|
||||||
module Bundler
|
module Bundler
|
||||||
|
@ -77,8 +78,8 @@ module Bundler
|
||||||
|
|
||||||
def contains?(commit)
|
def contains?(commit)
|
||||||
allowed_in_path do
|
allowed_in_path do
|
||||||
result = git_null("branch --contains #{commit}")
|
result, status = git_null("branch --contains #{commit}")
|
||||||
$? == 0 && result =~ /^\* (.*)$/
|
status.success? && result =~ /^\* (.*)$/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -148,13 +149,15 @@ module Bundler
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# TODO: Do not rely on /dev/null.
|
|
||||||
# Given that open3 is not cross platform until Ruby 1.9.3,
|
|
||||||
# the best solution is to pipe to /dev/null if it exists.
|
|
||||||
# If it doesn't, everything will work fine, but the user
|
|
||||||
# will get the $stderr messages as well.
|
|
||||||
def git_null(command)
|
def git_null(command)
|
||||||
git("#{command} 2>#{Bundler::NULL}", false)
|
command_with_no_credentials = URICredentialsFilter.credential_filtered_string(command, uri)
|
||||||
|
raise GitNotAllowedError.new(command_with_no_credentials) unless allow?
|
||||||
|
|
||||||
|
out, status = SharedHelpers.with_clean_git_env do
|
||||||
|
capture_and_ignore_stderr("git #{command}")
|
||||||
|
end
|
||||||
|
|
||||||
|
[URICredentialsFilter.credential_filtered_string(out, uri), status]
|
||||||
end
|
end
|
||||||
|
|
||||||
def git_retry(command)
|
def git_retry(command)
|
||||||
|
@ -167,12 +170,12 @@ module Bundler
|
||||||
command_with_no_credentials = URICredentialsFilter.credential_filtered_string(command, uri)
|
command_with_no_credentials = URICredentialsFilter.credential_filtered_string(command, uri)
|
||||||
raise GitNotAllowedError.new(command_with_no_credentials) unless allow?
|
raise GitNotAllowedError.new(command_with_no_credentials) unless allow?
|
||||||
|
|
||||||
out = SharedHelpers.with_clean_git_env do
|
out, status = SharedHelpers.with_clean_git_env do
|
||||||
capture_and_filter_stderr(uri) { `git #{command}` }
|
capture_and_filter_stderr(uri, "git #{command}")
|
||||||
end
|
end
|
||||||
|
|
||||||
stdout_with_no_credentials = URICredentialsFilter.credential_filtered_string(out, uri)
|
stdout_with_no_credentials = URICredentialsFilter.credential_filtered_string(out, uri)
|
||||||
raise GitCommandError.new(command_with_no_credentials, path, error_msg) if check_errors && !$?.success?
|
raise GitCommandError.new(command_with_no_credentials, path, error_msg) if check_errors && !status.success?
|
||||||
stdout_with_no_credentials
|
stdout_with_no_credentials
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -235,26 +238,15 @@ module Bundler
|
||||||
raise GitError, "The git source #{uri} is not yet checked out. Please run `bundle install` before trying to start your application"
|
raise GitError, "The git source #{uri} is not yet checked out. Please run `bundle install` before trying to start your application"
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: Replace this with Open3 when upgrading to bundler 2
|
def capture_and_filter_stderr(uri, cmd)
|
||||||
# Similar to #git_null, as Open3 is not cross-platform,
|
return_value, captured_err, status = Open3.capture3(cmd)
|
||||||
# a temporary way is to use Tempfile to capture the stderr.
|
|
||||||
# When replacing this using Open3, make sure git_null is
|
|
||||||
# also replaced by Open3, so stdout and stderr all got handled properly.
|
|
||||||
def capture_and_filter_stderr(uri)
|
|
||||||
return_value, captured_err = ""
|
|
||||||
backup_stderr = STDERR.dup
|
|
||||||
begin
|
|
||||||
Tempfile.open("captured_stderr") do |f|
|
|
||||||
STDERR.reopen(f)
|
|
||||||
return_value = yield
|
|
||||||
f.rewind
|
|
||||||
captured_err = f.read
|
|
||||||
end
|
|
||||||
ensure
|
|
||||||
STDERR.reopen backup_stderr
|
|
||||||
end
|
|
||||||
Bundler.ui.warn URICredentialsFilter.credential_filtered_string(captured_err, uri) if uri && !captured_err.empty?
|
Bundler.ui.warn URICredentialsFilter.credential_filtered_string(captured_err, uri) if uri && !captured_err.empty?
|
||||||
return_value
|
[return_value, status]
|
||||||
|
end
|
||||||
|
|
||||||
|
def capture_and_ignore_stderr(cmd)
|
||||||
|
return_value, _, status = Open3.capture3(cmd)
|
||||||
|
[return_value, status]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue