Handle Tap migration in Tap#initialize.
This commit is contained in:
parent
ff8d14fe2a
commit
b109e6da5d
@ -1,18 +1,38 @@
|
|||||||
module CaskTapMigrationExtension
|
module CaskTapMigration
|
||||||
def parse_user_repo(*args)
|
def initialize(user, repo)
|
||||||
user, repo = super
|
super
|
||||||
|
|
||||||
if user == "caskroom"
|
return unless user == "caskroom"
|
||||||
user = "Homebrew"
|
|
||||||
repo = "cask-#{repo}" unless repo == "cask"
|
|
||||||
end
|
|
||||||
|
|
||||||
[user, repo]
|
# TODO: Remove this check after migration.
|
||||||
|
return unless repo == "tap-migration-test"
|
||||||
|
|
||||||
|
new_user = "Homebrew"
|
||||||
|
new_repo = (repo == "cask") ? repo : "cask-#{repo}"
|
||||||
|
|
||||||
|
old_name = name
|
||||||
|
old_path = path
|
||||||
|
old_remote = path.git_origin
|
||||||
|
|
||||||
|
super(new_user, new_repo)
|
||||||
|
|
||||||
|
return unless old_path.git?
|
||||||
|
|
||||||
|
new_name = name
|
||||||
|
new_path = path
|
||||||
|
new_remote = default_remote
|
||||||
|
|
||||||
|
ohai "Migrating Tap #{old_name} to #{new_name} …"
|
||||||
|
|
||||||
|
puts "Moving #{old_path} to #{new_path} …"
|
||||||
|
path.dirname.mkpath
|
||||||
|
FileUtils.mv old_path, new_path
|
||||||
|
|
||||||
|
puts "Changing remote from #{old_remote} to #{new_remote} …"
|
||||||
|
new_path.git_origin = new_remote
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Tap
|
class Tap
|
||||||
class << self
|
prepend CaskTapMigration
|
||||||
prepend CaskTapMigrationExtension
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,6 +13,13 @@ module GitRepositoryExtension
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def git_origin=(origin)
|
||||||
|
return unless git? && Utils.git_available?
|
||||||
|
cd do
|
||||||
|
Utils.popen_read("git", "remote", "set-url", "origin", origin).chuzzle
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def git_head
|
def git_head
|
||||||
return unless git? && Utils.git_available?
|
return unless git? && Utils.git_available?
|
||||||
cd do
|
cd do
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class Tap
|
|||||||
|
|
||||||
TAP_DIRECTORY = HOMEBREW_LIBRARY/"Taps"
|
TAP_DIRECTORY = HOMEBREW_LIBRARY/"Taps"
|
||||||
|
|
||||||
def self.parse_user_repo(*args)
|
def self.fetch(*args)
|
||||||
case args.length
|
case args.length
|
||||||
when 1
|
when 1
|
||||||
user, repo = args.first.split("/", 2)
|
user, repo = args.first.split("/", 2)
|
||||||
@ -29,13 +29,6 @@ class Tap
|
|||||||
user = user.capitalize if ["homebrew", "linuxbrew"].include? user
|
user = user.capitalize if ["homebrew", "linuxbrew"].include? user
|
||||||
repo = repo.strip_prefix "homebrew-"
|
repo = repo.strip_prefix "homebrew-"
|
||||||
|
|
||||||
[user, repo]
|
|
||||||
end
|
|
||||||
private_class_method :parse_user_repo
|
|
||||||
|
|
||||||
def self.fetch(*args)
|
|
||||||
user, repo = parse_user_repo(*args)
|
|
||||||
|
|
||||||
if ["Homebrew", "Linuxbrew"].include?(user) && ["core", "homebrew"].include?(repo)
|
if ["Homebrew", "Linuxbrew"].include?(user) && ["core", "homebrew"].include?(repo)
|
||||||
return CoreTap.instance
|
return CoreTap.instance
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user