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 <mike@mikemcquaid.com>
This commit is contained in:
Martin Afanasjew 2015-08-19 16:02:24 +02:00 committed by Mike McQuaid
parent fc445d97d3
commit 1288e3110d
2 changed files with 10 additions and 3 deletions

View File

@ -194,6 +194,8 @@ class Updater
reset_on_interrupt { safe_system "git", *args } reset_on_interrupt { safe_system "git", *args }
@current_revision = read_current_revision
if @initial_branch != "master" && !@initial_branch.empty? if @initial_branch != "master" && !@initial_branch.empty?
safe_system "git", "checkout", @initial_branch, *quiet safe_system "git", "checkout", @initial_branch, *quiet
end end
@ -206,8 +208,6 @@ class Updater
end end
@stashed = false @stashed = false
end end
@current_revision = read_current_revision
end end
def reset_on_interrupt def reset_on_interrupt
@ -224,6 +224,8 @@ class Updater
map = Hash.new { |h, k| h[k] = [] } map = Hash.new { |h, k| h[k] = [] }
if initial_revision && initial_revision != current_revision if initial_revision && initial_revision != current_revision
wc_revision = read_current_revision
diff.each_line do |line| diff.each_line do |line|
status, *paths = line.split status, *paths = line.split
src = paths.first src = paths.first
@ -239,7 +241,11 @@ class Updater
file = repository.join(src) file = repository.join(src)
begin begin
formula = Formulary.factory(file) 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) old_version = FormulaVersions.new(formula).formula_at_revision(@initial_revision, &:pkg_version)
next if new_version == old_version next if new_version == old_version
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS => e rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS => e

View File

@ -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 pull --quiet origin refs/heads/master:refs/remotes/origin/master")
@updater.in_repo_expect("git rev-parse -q --verify HEAD", "3456cdef") @updater.in_repo_expect("git rev-parse -q --verify HEAD", "3456cdef")
@updater.pull!(:silent => true) @updater.pull!(:silent => true)
@updater.in_repo_expect("git rev-parse -q --verify HEAD", "3456cdef")
@report.update(@updater.report) @report.update(@updater.report)
assert_equal @updater.expected, @updater.called assert_equal @updater.expected, @updater.called
end end