migrator: check if taps are from same user instead

This avoids needing to use `force: true` and still let's Homebrew do
what we want with our own taps.
This commit is contained in:
Mike McQuaid 2017-03-31 10:28:45 +01:00
parent dd7121dd7c
commit 7d07d859ce
2 changed files with 11 additions and 13 deletions

View File

@ -525,12 +525,7 @@ class Reporter
next
end
begin
migrator = Migrator.new(f, force: true)
migrator.migrate
rescue Exception => e
onoe e
end
Migrator.migrate_if_needed(f)
end
end

View File

@ -95,7 +95,7 @@ class Migrator
def self.migrate_if_needed(formula)
return unless Migrator.needs_migration?(formula)
begin
migrator = Migrator.new(formula, force: true)
migrator = Migrator.new(formula)
migrator.migrate
rescue Exception => e
onoe e
@ -114,7 +114,7 @@ class Migrator
@old_tabs = old_cellar.subdirs.map { |d| Tab.for_keg(Keg.new(d)) }
@old_tap = old_tabs.first.tap
if !force && !from_same_taps?
if !force && !from_same_tap_user?
raise MigratorDifferentTapsError.new(formula, old_tap)
end
@ -140,15 +140,19 @@ class Migrator
end
end
def from_same_taps?
def from_same_tap_user?
formula_tap_user = formula.tap.user if formula.tap
old_tap_user = nil
new_tap = if old_tap
old_tap_user, = old_tap.user
if migrate_tap = old_tap.tap_migrations[formula.oldname]
new_tap_user, new_tap_repo, = migrate_tap.split("/")
new_tap_user, new_tap_repo = migrate_tap.split("/")
"#{new_tap_user}/#{new_tap_repo}"
end
end
if formula.tap == old_tap
if formula_tap_user == old_tap_user
true
# Homebrew didn't use to update tabs while performing tap-migrations,
# so there can be INSTALL_RECEIPT's containing wrong information about tap,
@ -215,8 +219,7 @@ class Migrator
end
if conflicted
onoe "Remove #{new_cellar} manually and run brew migrate #{oldname}."
return
odie "Remove #{new_cellar} manually and run brew migrate #{oldname}."
end
end