aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils/github.rb
diff options
context:
space:
mode:
authorMartin Afanasjew2016-07-25 07:53:12 +0200
committerMartin Afanasjew2016-07-27 21:27:25 +0200
commitbdc1991d7792f495a540fe775da01f408cc4c640 (patch)
treea158b5ec9581004c1f3e3736ff97b4b9b4c8aed5 /Library/Homebrew/utils/github.rb
parentd4b5b2080d2083580f482e8f7cd5745ca9ebdfe4 (diff)
downloadbrew-bdc1991d7792f495a540fe775da01f408cc4c640.tar.bz2
utils/github: fix broken pipe error
Closes #573.
Diffstat (limited to 'Library/Homebrew/utils/github.rb')
-rw-r--r--Library/Homebrew/utils/github.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb
index c5dbedd6c..7f0b94567 100644
--- a/Library/Homebrew/utils/github.rb
+++ b/Library/Homebrew/utils/github.rb
@@ -52,11 +52,7 @@ module GitHub
elsif ENV["HOMEBREW_GITHUB_API_USERNAME"] && ENV["HOMEBREW_GITHUB_API_PASSWORD"]
[ENV["HOMEBREW_GITHUB_API_USERNAME"], ENV["HOMEBREW_GITHUB_API_PASSWORD"]]
else
- github_credentials = Utils.popen("git credential-osxkeychain get", "w+") do |io|
- io.puts "protocol=https\nhost=github.com"
- io.close_write
- io.read
- end
+ github_credentials = api_credentials_from_keychain
github_username = github_credentials[/username=(.+)/, 1]
github_password = github_credentials[/password=(.+)/, 1]
if github_username && github_password
@@ -68,6 +64,20 @@ module GitHub
end
end
+ def api_credentials_from_keychain
+ Utils.popen(["git", "credential-osxkeychain", "get"], "w+") do |pipe|
+ pipe.write "protocol=https\nhost=github.com\n"
+ pipe.close_write
+ pipe.read
+ end
+ rescue Errno::EPIPE
+ # The above invocation via `Utils.popen` can fail, causing the pipe to be
+ # prematurely closed (before we can write to it) and thus resulting in a
+ # broken pipe error. The root cause is usually a missing or malfunctioning
+ # `git-credential-osxkeychain` helper.
+ ""
+ end
+
def api_credentials_type
token, username = api_credentials
if token && !token.empty?