From 6d1c6dcdeae8eb90d5679faa53c82dcc1574d017 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 17 Feb 2013 15:53:34 -0600 Subject: [PATCH] GitDownloadStrategy: reset after checkout during updates Otherwise, if the local branch is behind the remote branch, or has diverged, we will stage the wrong revision. --- Library/Homebrew/download_strategy.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 8cb429da7a..25320c0048 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -322,6 +322,7 @@ class GitDownloadStrategy < AbstractDownloadStrategy config_repo update_repo checkout + reset update_submodules if submodules? end elsif @clone.exist? @@ -339,10 +340,7 @@ class GitDownloadStrategy < AbstractDownloadStrategy if @spec and @ref ohai "Checking out #@spec #@ref" else - # otherwise the checkout-index won't checkout HEAD - # https://github.com/mxcl/homebrew/issues/7124 - # must specify origin/HEAD, otherwise it resets to the current local HEAD - quiet_safe_system @@git, "reset", { :quiet_flag => "-q" }, "--hard", "origin/HEAD" + reset end # http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export safe_system @@git, 'checkout-index', '-a', '-f', "--prefix=#{dst}/" @@ -426,6 +424,22 @@ class GitDownloadStrategy < AbstractDownloadStrategy nostdout { quiet_safe_system @@git, *checkout_args } end + def reset_args + ref = case @spec + when :branch then "origin/#@ref" + when :revision, :tag then @ref + else "origin/HEAD" + end + + args = %w{reset} + args << { :quiet_flag => "-q" } + args << "--hard" << ref + end + + def reset + quiet_safe_system @@git, *reset_args + end + def update_submodules safe_system @@git, 'submodule', 'update', '--init' end