diff options
Diffstat (limited to 'Library/Homebrew/cmd')
| -rw-r--r-- | Library/Homebrew/cmd/update.rb | 57 | 
1 files changed, 36 insertions, 21 deletions
diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb index 10b4da661..6ee2726a9 100644 --- a/Library/Homebrew/cmd/update.rb +++ b/Library/Homebrew/cmd/update.rb @@ -203,15 +203,6 @@ class Updater    end    def pull!(options = {}) -    unless system "git", "diff", "--quiet" -      if ARGV.verbose? -        puts "Stashing your changes:" -        system "git", "status", "--short", "--untracked-files" -      end -      safe_system "git", "stash", "save", "--include-untracked", *@quiet_args -      @stashed = true -    end -      # The upstream repository's default branch may not be master;      # check refs/remotes/origin/HEAD to see what the default      # origin branch name is, and use that. If not set, fall back to "master". @@ -228,6 +219,16 @@ class Updater        @initial_branch = ""      end +    unless `git status --untracked-files=all --porcelain 2>/dev/null`.chomp.empty? +      if ARGV.verbose? +        puts "Stashing uncommitted changes to #{repository}." +        system "git", "status", "--short", "--untracked-files=all" +      end +      safe_system "git", "stash", "save", "--include-untracked", *@quiet_args +      safe_system "git", "reset", "--hard", *@quiet_args +      @stashed = true +    end +      # Used for testing purposes, e.g., for testing formula migration after      # renaming it in the currently checked-out branch. To test run      # "brew update --simulate-from-current-branch" @@ -243,7 +244,7 @@ class Updater      end      if @initial_branch != @upstream_branch && !@initial_branch.empty? -      safe_system "git", "checkout", @upstream_branch, *@quiet_args +      safe_system "git", "checkout", "--force", "-B", @upstream_branch, "origin/#{@upstream_branch}", *@quiet_args      end      @initial_revision = read_current_revision @@ -263,18 +264,29 @@ class Updater      @current_revision = read_current_revision -    if @initial_branch != "master" && !@initial_branch.empty? +    if @initial_branch != @upstream_branch && !@initial_branch.empty?        safe_system "git", "checkout", @initial_branch, *@quiet_args +      pop_stash +    else +      pop_stash_message      end +  end -    if @stashed -      safe_system "git", "stash", "pop", *@quiet_args -      if ARGV.verbose? -        puts "Restored your changes:" -        system "git", "status", "--short", "--untracked-files" -      end -      @stashed = false +  def pop_stash +    return unless @stashed +    safe_system "git", "stash", "pop", *@quiet_args +    if ARGV.verbose? +      puts "Restoring your stashed changes to #{repository}:" +      system "git", "status", "--short", "--untracked-files"      end +    @stashed = false +  end + +  def pop_stash_message +    return unless @stashed +    puts "To restore the stashed changes to #{repository} run:" +    puts "  `cd #{repository} && git stash pop`" +    @stashed = false    end    def reset_on_interrupt @@ -282,9 +294,12 @@ class Updater    ensure      if $?.signaled? && $?.termsig == 2 # SIGINT        safe_system "git", "checkout", @initial_branch unless @initial_branch.empty? -      safe_system "git", "reset", "--hard", @initial_revision -      safe_system "git", "stash", "pop", *@quiet_args if @stashed -      @stashed = false +      safe_system "git", "reset", "--hard", @initial_revision, *@quiet_args +      if @initial_branch +        pop_stash +      else +        pop_stash_message +      end      end    end  | 
