From 0ae1785703cc816725c78bbff4b390b918d6fd29 Mon Sep 17 00:00:00 2001 From: Uladzislau Shablinski Date: Thu, 20 Oct 2016 01:50:59 +0300 Subject: formula: use names for formula comparison * Causes a bug in Formula#installed_alias_target_changed? when Formula#superseds_an_installed_formula? returns true because Formula#old_installed_formulae includes f for some Formula f. * Causes a bug when foo@2.4 with alias foo has HEAD or devel version and we try to `brew upgrade foo --devel|--HEAD` from stable. The upgrade fails while since we installing formula to the same prefix it's alredy installed. The reason for that is that we use `formula_to_install = outdated.map(&:latest_formula)` in cmd/upgrade before calling upgrade_formula on foo. ```ruby def latest_formula installed_alias_target_changed? ? current_installed_alias_target : self end ``` Formula#installed_alias_target_changed? compares formulae using Formula#==, which is wrong for this case, thus Formula#latest_formula doesn't return self and returns Formula#current_installed_alias_target with spec foo was initially installed instead of devel or HEAD, causing the error. --- Library/Homebrew/formula.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 4d3c143dc..69cab88c4 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1167,7 +1167,7 @@ class Formula # Returns false if the formula wasn't installed with an alias. def installed_alias_target_changed? target = current_installed_alias_target - target && target != self + target && target.name != name end # Is this formula the target of an alias used to install an old formula? @@ -1192,7 +1192,7 @@ class Formula # it doesn't make sense to say that other formulae are older versions of it # because we don't know which came first. return [] if alias_path.nil? || installed_alias_target_changed? - self.class.installed_with_alias_path(alias_path) - [self] + self.class.installed_with_alias_path(alias_path).reject { |f| f.name == name } end # @private -- cgit v1.2.3 From 4ec43d02f5c4b85de69a2103ba6e5d0d72dfc15f Mon Sep 17 00:00:00 2001 From: Uladzislau Shablinski Date: Thu, 20 Oct 2016 02:42:50 +0300 Subject: test_formula: fix tests New name and old name must have different names --- Library/Homebrew/test/test_formula.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb index 37d3f0f59..a12983e4c 100644 --- a/Library/Homebrew/test/test_formula.rb +++ b/Library/Homebrew/test/test_formula.rb @@ -799,8 +799,8 @@ end class AliasChangeTests < Homebrew::TestCase attr_reader :f, :new_formula, :tab, :alias_path - def make_formula(version) - f = formula(alias_path: alias_path) { url "foo-#{version}" } + def make_formula(name, version) + f = formula(name, alias_path: alias_path) { url "foo-#{version}" } f.build = tab f end @@ -811,8 +811,8 @@ class AliasChangeTests < Homebrew::TestCase @tab = Tab.empty - @f = make_formula("1.0") - @new_formula = make_formula("1.1") + @f = make_formula("formula_name", "1.0") + @new_formula = make_formula("new_formula_name", "1.1") Formula.stubs(:installed).returns([f]) end -- cgit v1.2.3