aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew
diff options
context:
space:
mode:
Diffstat (limited to 'Library/Homebrew')
-rw-r--r--Library/Homebrew/cmd/tap.rb29
-rw-r--r--Library/Homebrew/utils.rb8
2 files changed, 23 insertions, 14 deletions
diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb
index 58132faca..cc8f63d0f 100644
--- a/Library/Homebrew/cmd/tap.rb
+++ b/Library/Homebrew/cmd/tap.rb
@@ -31,20 +31,14 @@ module Homebrew extend self
link_tap_formula(files)
puts "Tapped #{files.length} formula"
- # Figure out if this repo is private
- # curl will throw an exception if the repo is private (Github returns a 404)
- begin
- curl('-Ifso', '/dev/null', "https://api.github.com/repos/#{repouser}/homebrew-#{repo}")
- rescue
- puts
- puts "It looks like you tapped a private repository"
- puts "In order to not input your credentials every time"
- puts "you can use git HTTP credential caching or issue the"
- puts "following command:"
- puts
- puts " cd #{tapd}"
- puts " git remote set-url origin git@github.com:#{repouser}/homebrew-#{repo}.git"
- puts
+ if private_tap?(repouser, repo) then puts <<-EOS.undent
+ It looks like you tapped a private repository. To avoid entering your
+ credentials each time you update, you can use git HTTP credential caching
+ or issue the following command:
+
+ cd #{tapd}
+ git remote set-url origin git@github.com:#{repouser}/homebrew-#{repo}.git
+ EOS
end
true
@@ -114,6 +108,13 @@ module Homebrew extend self
[$1, $3]
end
+ def private_tap?(user, repo)
+ GitHub.private_repo?(user, "homebrew-#{repo}")
+ rescue GitHub::HTTPNotFoundError => e
+ true
+ rescue GitHub::Error
+ false
+ end
end
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 6ec85a714..ed1f691d0 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -253,6 +253,7 @@ module GitHub extend self
Error = Class.new(StandardError)
RateLimitExceededError = Class.new(Error)
+ HTTPNotFoundError = Class.new(Error)
def open url, headers={}, &block
# This is a no-op if the user is opting out of using the GitHub API.
@@ -276,6 +277,8 @@ module GitHub extend self
You may want to create an API token: https://github.com/settings/applications
and then set HOMEBREW_GITHUB_API_TOKEN.
EOS
+ elsif e.io.status.first == "404"
+ raise HTTPNotFoundError, e.message, e.backtrace
else
raise Error, e.message, e.backtrace
end
@@ -334,4 +337,9 @@ module GitHub extend self
prs.each {|i| yield "#{i["title"]} (#{i["pull_request"]["html_url"]})" }
end
+
+ def private_repo?(user, repo)
+ uri = URI.parse("https://api.github.com/repos/#{user}/#{repo}")
+ open(uri) { |json| json["private"] }
+ end
end