implement pinning of taps
This commit is contained in:
parent
fda82b0b64
commit
1a82b2133e
13
Library/Homebrew/cmd/tap-pin.rb
Normal file
13
Library/Homebrew/cmd/tap-pin.rb
Normal file
@ -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
|
||||||
13
Library/Homebrew/cmd/tap-unpin.rb
Normal file
13
Library/Homebrew/cmd/tap-unpin.rb
Normal file
@ -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
|
||||||
@ -10,6 +10,8 @@ module Homebrew
|
|||||||
raise TapUnavailableError, tap.name unless tap.installed?
|
raise TapUnavailableError, tap.name unless tap.installed?
|
||||||
puts "Untapping #{tap}... (#{tap.path.abv})"
|
puts "Untapping #{tap}... (#{tap.path.abv})"
|
||||||
|
|
||||||
|
tap.unpin if tap.pinned?
|
||||||
|
|
||||||
formula_count = tap.formula_files.size
|
formula_count = tap.formula_files.size
|
||||||
tap.path.rmtree
|
tap.path.rmtree
|
||||||
tap.path.dirname.rmdir_if_possible
|
tap.path.dirname.rmdir_if_possible
|
||||||
|
|||||||
@ -98,6 +98,17 @@ class TapUnavailableError < RuntimeError
|
|||||||
end
|
end
|
||||||
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
|
class OperationInProgressError < RuntimeError
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
message = <<-EOS.undent
|
message = <<-EOS.undent
|
||||||
|
|||||||
@ -99,6 +99,27 @@ class Tap
|
|||||||
Pathname.glob("#{path}/cmd/brew-*").select(&:executable?)
|
Pathname.glob("#{path}/cmd/brew-*").select(&:executable?)
|
||||||
end
|
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
|
def to_hash
|
||||||
{
|
{
|
||||||
"name" => @name,
|
"name" => @name,
|
||||||
@ -111,7 +132,8 @@ class Tap
|
|||||||
"custom_remote" => custom_remote?,
|
"custom_remote" => custom_remote?,
|
||||||
"formula_names" => formula_names,
|
"formula_names" => formula_names,
|
||||||
"formula_files" => formula_files.map(&:to_s),
|
"formula_files" => formula_files.map(&:to_s),
|
||||||
"command_files" => command_files.map(&:to_s)
|
"command_files" => command_files.map(&:to_s),
|
||||||
|
"pinned" => pinned?
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user