aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2016-04-12 18:51:43 +0800
committerXu Cheng2016-04-12 18:51:43 +0800
commit548be81b34517e194c606c632373ffba8b412c34 (patch)
tree8ce958f19637576458542e789728ca5f433b1e63 /Library
parentf57739deda5a1ee099d1acab18384a130a9b95ad (diff)
downloadbrew-548be81b34517e194c606c632373ffba8b412c34.tar.bz2
tap: various improvements (#77)
* make `read_or_set_private_config` private * add doc * add test
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/tap.rb46
-rw-r--r--Library/Homebrew/test/test_tap.rb10
2 files changed, 35 insertions, 21 deletions
diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb
index a84aded79..042f1af52 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 0b2671698..a6b81dc95 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