Skip to content

Commit

Permalink
utils/github: fix broken pipe error
Browse files Browse the repository at this point in the history
Closes Homebrew#573.
  • Loading branch information
UniqMartin committed Jul 27, 2016
1 parent d4b5b20 commit bdc1991
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Library/Homebrew/utils/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ def api_credentials
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
Expand All @@ -68,6 +64,20 @@ def api_credentials
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?
Expand Down

0 comments on commit bdc1991

Please sign in to comment.