utils: API Git credential tweaks.

- Use empty array when `git credential-osxkeychain` lookup fails to
  cache and avoid rerunning it when there's no valid results.
- Redirect `stderr` to avoid printing errors when there's a failure
  or no `git credential-osxkeychain` installed.

Closes Homebrew/homebrew#49954.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Mike McQuaid 2016-03-10 10:24:08 +00:00 committed by Xu Cheng
parent 0f6def90b7
commit c8debd8fa4

View File

@ -511,14 +511,18 @@ module GitHub
if ENV["HOMEBREW_GITHUB_API_TOKEN"]
ENV["HOMEBREW_GITHUB_API_TOKEN"]
else
github_credentials = IO.popen("git credential-osxkeychain get", "w+") do |io|
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_username = github_credentials[/username=(.+)/, 1]
github_password = github_credentials[/password=(.+)/, 1]
[github_password, github_username] if github_username && github_password
if github_username && github_password
[github_password, github_username]
else
[]
end
end
end
end