From 548be81b34517e194c606c632373ffba8b412c34 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Tue, 12 Apr 2016 18:51:43 +0800 Subject: [PATCH] tap: various improvements (#77) * make `read_or_set_private_config` private * add doc * add test --- Library/Homebrew/tap.rb | 46 +++++++++++++++++-------------- Library/Homebrew/test/test_tap.rb | 10 +++++++ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index a84aded796..042f1af524 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -145,32 +145,13 @@ class Tap user == "Homebrew" end - # @private - def read_and_set_private_config - case config["private"] - when "true" then true - when "false" then false - else - config["private"] = begin - if custom_remote? - true - else - GitHub.private_repo?(user, "homebrew-#{repo}") - end - rescue GitHub::HTTPNotFoundError - true - rescue GitHub::Error - false - end - end - end - # True if the remote of this {Tap} is a private repository. def private? return @private if instance_variable_defined?(:@private) - @private = read_and_set_private_config + @private = read_or_set_private_config end + # {TapConfig} of this {Tap} def config @config ||= begin raise TapUnavailableError, name unless installed? @@ -489,6 +470,28 @@ class Tap def alias_file_to_name(file) "#{name}/#{file.basename}" end + + private + + def read_or_set_private_config + case config["private"] + when "true" then true + when "false" then false + else + config["private"] = begin + if custom_remote? + true + else + GitHub.private_repo?(user, "homebrew-#{repo}") + end + rescue GitHub::HTTPNotFoundError + true + rescue GitHub::Error + false + end + end + end + end # A specialized {Tap} class for the core formulae @@ -593,6 +596,7 @@ class CoreTap < Tap end end +# Permanent configuration per {Tap} using `git-config(1)` class TapConfig attr_reader :tap diff --git a/Library/Homebrew/test/test_tap.rb b/Library/Homebrew/test/test_tap.rb index 0b26716986..a6b81dc958 100644 --- a/Library/Homebrew/test/test_tap.rb +++ b/Library/Homebrew/test/test_tap.rb @@ -231,6 +231,16 @@ class TapTest < Homebrew::TestCase @tap.unpin refute_predicate @tap, :pinned? end + + def test_config + setup_git_repo + + assert_nil @tap.config["foo"] + @tap.config["foo"] = "bar" + assert_equal "bar", @tap.config["foo"] + @tap.config["foo"] = nil + assert_nil @tap.config["foo"] + end end class CoreTapTest < Homebrew::TestCase