diff options
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/cmd/tap-pin.rb | 13 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/tap-unpin.rb | 13 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/untap.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/exceptions.rb | 11 | ||||
| -rw-r--r-- | Library/Homebrew/tap.rb | 24 |
5 files changed, 62 insertions, 1 deletions
diff --git a/Library/Homebrew/cmd/tap-pin.rb b/Library/Homebrew/cmd/tap-pin.rb new file mode 100644 index 000000000..8cc5d87f8 --- /dev/null +++ b/Library/Homebrew/cmd/tap-pin.rb @@ -0,0 +1,13 @@ +require "cmd/tap" + +module Homebrew + def tap_pin + taps = ARGV.named.map do |name| + Tap.new(*tap_args(name)) + end + taps.each do |tap| + tap.pin + ohai "Pinned #{tap.name}" + end + end +end diff --git a/Library/Homebrew/cmd/tap-unpin.rb b/Library/Homebrew/cmd/tap-unpin.rb new file mode 100644 index 000000000..c20fb8dda --- /dev/null +++ b/Library/Homebrew/cmd/tap-unpin.rb @@ -0,0 +1,13 @@ +require "cmd/tap" + +module Homebrew + def tap_unpin + taps = ARGV.named.map do |name| + Tap.new(*tap_args(name)) + end + taps.each do |tap| + tap.unpin + ohai "Unpinned #{tap.name}" + end + end +end diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index 793ad299d..1e8bfdcab 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -10,6 +10,8 @@ module Homebrew raise TapUnavailableError, tap.name unless tap.installed? puts "Untapping #{tap}... (#{tap.path.abv})" + tap.unpin if tap.pinned? + formula_count = tap.formula_files.size tap.path.rmtree tap.path.dirname.rmdir_if_possible diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 841cc8b39..d49630e0e 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -98,6 +98,17 @@ class TapUnavailableError < RuntimeError end end +class TapPinStatusError < RuntimeError + attr_reader :name, :pinned + + def initialize name, pinned + @name = name + @pinned = pinned + + super pinned ? "#{name} is already pinned." : "#{name} is already unpinned." + end +end + class OperationInProgressError < RuntimeError def initialize(name) message = <<-EOS.undent diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 217261eca..2e12e4844 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -99,6 +99,27 @@ class Tap Pathname.glob("#{path}/cmd/brew-*").select(&:executable?) end + def pinned_symlink_path + HOMEBREW_LIBRARY/"PinnedTaps/#{@name}" + end + + def pinned? + @pinned ||= pinned_symlink_path.directory? + end + + def pin + raise TapUnavailableError, name unless installed? + raise TapPinStatusError.new(name, true) if pinned? + pinned_symlink_path.make_relative_symlink(@path) + end + + def unpin + raise TapUnavailableError, name unless installed? + raise TapPinStatusError.new(name, false) unless pinned? + pinned_symlink_path.delete + pinned_symlink_path.dirname.rmdir_if_possible + end + def to_hash { "name" => @name, @@ -111,7 +132,8 @@ class Tap "custom_remote" => custom_remote?, "formula_names" => formula_names, "formula_files" => formula_files.map(&:to_s), - "command_files" => command_files.map(&:to_s) + "command_files" => command_files.map(&:to_s), + "pinned" => pinned? } end |
