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 | |
| 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')
| -rw-r--r-- | Library/Homebrew/cmd/update.rb | 57 | ||||
| -rw-r--r-- | Library/Homebrew/test/test_updater.rb | 2 |
2 files changed, 37 insertions, 22 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 diff --git a/Library/Homebrew/test/test_updater.rb b/Library/Homebrew/test/test_updater.rb index 20d26e6e9..16efdaa1d 100644 --- a/Library/Homebrew/test/test_updater.rb +++ b/Library/Homebrew/test/test_updater.rb @@ -57,9 +57,9 @@ class UpdaterTests < Homebrew::TestCase Formulary.stubs(:factory).returns(stub(:pkg_version => "1.0")) FormulaVersions.stubs(:new).returns(stub(:formula_at_revision => "2.0")) @updater.diff = fixture(fixture_name) - @updater.in_repo_expect("git diff --quiet", true) @updater.in_repo_expect("git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null", "refs/remotes/origin/master") @updater.in_repo_expect("git symbolic-ref --short HEAD 2>/dev/null", "master") + @updater.in_repo_expect("git status --untracked-files=all --porcelain 2>/dev/null", "") @updater.in_repo_expect("git rev-parse -q --verify HEAD", "1234abcd") @updater.in_repo_expect("git config core.autocrlf false") @updater.in_repo_expect("git pull --ff --no-rebase --quiet origin refs/heads/master:refs/remotes/origin/master") |
