diff options
| author | Mike McQuaid | 2015-07-09 12:33:31 +0100 |
|---|---|---|
| committer | Mike McQuaid | 2015-07-09 12:33:31 +0100 |
| commit | b11ae2abdcb1ab91000109a4852f92ba2de0c285 (patch) | |
| tree | e5a32f36f634fc14b208f9a4e9f9a8b9c79faf3e /Library/Homebrew/cmd | |
| parent | 7c890261ac500da49acd801aebe244d9d12f93e3 (diff) | |
| download | brew-b11ae2abdcb1ab91000109a4852f92ba2de0c285.tar.bz2 | |
update: stash save/pop uncommitted changes.
Also:
- return to your previous branch after `brew update`.
Closes Homebrew/homebrew#38568.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
Diffstat (limited to 'Library/Homebrew/cmd')
| -rw-r--r-- | Library/Homebrew/cmd/update.rb | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb index c01fb827a..37610956a 100644 --- a/Library/Homebrew/cmd/update.rb +++ b/Library/Homebrew/cmd/update.rb @@ -122,25 +122,53 @@ class Updater def initialize(repository) @repository = repository + @stashed = false end - def pull! - safe_system "git", "checkout", "-q", "master" + def pull!(options={}) + quiet = [] + quiet << "--quiet" unless ARGV.verbose? + + unless system "git", "diff", "--quiet" + unless options[:silent] + puts "Stashing your changes:" + system "git", "status", "--short", "--untracked-files" + end + safe_system "git", "stash", "save", "--include-untracked", *quiet + @stashed = true + end + + @initial_branch = `git symbolic-ref --short HEAD`.chomp + if @initial_branch != "master" && !@initial_branch.empty? + safe_system "git", "checkout", "master", *quiet + end @initial_revision = read_current_revision # ensure we don't munge line endings on checkout safe_system "git", "config", "core.autocrlf", "false" - args = ["pull"] + args = ["pull", "origin"] args << "--rebase" if ARGV.include? "--rebase" - args << "-q" unless ARGV.verbose? - args << "origin" # the refspec ensures that 'origin/master' gets updated args << "refs/heads/master:refs/remotes/origin/master" + args += quiet reset_on_interrupt { safe_system "git", *args } + if @initial_branch != "master" && !@initial_branch.empty? + safe_system "git", "checkout", @initial_branch, *quiet + end + + if @stashed + safe_system "git", "stash", "pop", *quiet + unless options[:silent] + puts "Restored your changes:" + system "git", "status", "--short", "--untracked-files" + end + @stashed = false + end + @current_revision = read_current_revision end @@ -148,7 +176,9 @@ class Updater ignore_interrupts { yield } ensure if $?.signaled? && $?.termsig == 2 # SIGINT + safe_system "git", "checkout", @initial_branch safe_system "git", "reset", "--hard", @initial_revision + safe_system "git", "stash", "pop" if @stashed end end |
