diff options
| author | Mike McQuaid | 2015-12-07 09:30:19 +0000 |
|---|---|---|
| committer | Mike McQuaid | 2015-12-07 13:37:27 +0000 |
| commit | fe8a0569ca1fc419f80196bea22cc1de0ff3b93a (patch) | |
| tree | 71cee24a2966ebdcd1c9a4113a3bc76b7edafc2e /Library/Homebrew/cmd | |
| parent | 3d3c3e013108a3d21ad188488e69f8b33227537b (diff) | |
| download | brew-fe8a0569ca1fc419f80196bea22cc1de0ff3b93a.tar.bz2 | |
update: always reset to origin/master.
Do a reset to `origin/master` and then stash but don't pop the stash
after running update (unless you were on a branch). This may be mildly
more annoying for Homebrew developers but means it's easier for our
users who don't understand Git (and particularly when they don't
understand that every tap is a separate Git repository).
Closes Homebrew/homebrew#45825.
Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
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 |
