diff options
author | Homu <homu@barosl.com> | 2016-08-16 14:49:14 +0900 |
---|---|---|
committer | Homu <homu@barosl.com> | 2016-08-16 14:49:14 +0900 |
commit | e9591fde543516ed800cde933d9f06e7e20e6077 (patch) | |
tree | 44f98927c4ca411fd9d3f780b41a1bd650f50b23 /lib | |
parent | b148a85de7e49fcc337c66af481731501c83214d (diff) | |
parent | eb113bf747640db761f89e97e66e8f76c4fd153b (diff) | |
download | bundler-e9591fde543516ed800cde933d9f06e7e20e6077.tar.gz |
Auto merge of #4704 - allenzhao:issue-4663, r=indirect
Filter out credentials in stderr message
This will close #4663
- [x] Fix broken tests
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/source/git/git_proxy.rb | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb index 693492f3d2..4b76d18735 100644 --- a/lib/bundler/source/git/git_proxy.rb +++ b/lib/bundler/source/git/git_proxy.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +require "tempfile" module Bundler class Source class Git < Path @@ -156,7 +157,9 @@ module Bundler command_with_no_credentials = URICredentialsFilter.credential_filtered_string(command, uri) raise GitNotAllowedError.new(command_with_no_credentials) unless allow? - out = SharedHelpers.with_clean_git_env { `git #{command}` } + out = SharedHelpers.with_clean_git_env do + capture_and_filter_stderr(uri) { `git #{command}` } + end stdout_with_no_credentials = URICredentialsFilter.credential_filtered_string(out, uri) raise GitCommandError.new(command_with_no_credentials, path, error_msg) if check_errors && !$?.success? @@ -220,6 +223,23 @@ module Bundler return in_path { yield } if allow? raise GitError, "The git source #{uri} is not yet checked out. Please run `bundle install` before trying to start your application" end + + 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 + $stderr.puts URICredentialsFilter.credential_filtered_string(captured_err, uri) if uri && !captured_err.empty? + return_value + end end end end |