From 1288e3110d5b59a3d49e8f0e01e7537235309ae9 Mon Sep 17 00:00:00 2001 From: Martin Afanasjew Date: Wed, 19 Aug 2015 16:02:24 +0200 Subject: [PATCH] update: always report changes to branch 'master' If the user's working copy is *not* on the 'master' branch, the revision recorded after the update to the 'master' branch is not the one of the updated 'master' branch but that of whatever the user's current branch is. This tends to be not very helpful. This change records the revision *after* the update to the 'master' branch, but *before* switching back to the user's current branch prior to the update, effectively causing the report to show changes to the 'master' branch. Closes Homebrew/homebrew#42074. Signed-off-by: Mike McQuaid --- Library/Homebrew/cmd/update.rb | 12 +++++++++--- Library/Homebrew/test/test_updater.rb | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb index 200f039792..83350988b5 100644 --- a/Library/Homebrew/cmd/update.rb +++ b/Library/Homebrew/cmd/update.rb @@ -194,6 +194,8 @@ class Updater reset_on_interrupt { safe_system "git", *args } + @current_revision = read_current_revision + if @initial_branch != "master" && !@initial_branch.empty? safe_system "git", "checkout", @initial_branch, *quiet end @@ -206,8 +208,6 @@ class Updater end @stashed = false end - - @current_revision = read_current_revision end def reset_on_interrupt @@ -224,6 +224,8 @@ class Updater map = Hash.new { |h, k| h[k] = [] } if initial_revision && initial_revision != current_revision + wc_revision = read_current_revision + diff.each_line do |line| status, *paths = line.split src = paths.first @@ -239,7 +241,11 @@ class Updater file = repository.join(src) begin formula = Formulary.factory(file) - new_version = formula.pkg_version + new_version = if wc_revision == current_revision + formula.pkg_version + else + FormulaVersions.new(formula).formula_at_revision(@current_revision, &:pkg_version) + end old_version = FormulaVersions.new(formula).formula_at_revision(@initial_revision, &:pkg_version) next if new_version == old_version rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS => e diff --git a/Library/Homebrew/test/test_updater.rb b/Library/Homebrew/test/test_updater.rb index 9c3c029796..87e175ea3a 100644 --- a/Library/Homebrew/test/test_updater.rb +++ b/Library/Homebrew/test/test_updater.rb @@ -64,6 +64,7 @@ class UpdaterTests < Homebrew::TestCase @updater.in_repo_expect("git pull --quiet origin refs/heads/master:refs/remotes/origin/master") @updater.in_repo_expect("git rev-parse -q --verify HEAD", "3456cdef") @updater.pull!(:silent => true) + @updater.in_repo_expect("git rev-parse -q --verify HEAD", "3456cdef") @report.update(@updater.report) assert_equal @updater.expected, @updater.called end