diff options
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cmd/update.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Library/Homebrew/cmd/update.rb b/Library/Homebrew/cmd/update.rb index 08062e15b..9e2541434 100644 --- a/Library/Homebrew/cmd/update.rb +++ b/Library/Homebrew/cmd/update.rb @@ -247,7 +247,13 @@ class Updater end if @initial_branch != @upstream_branch && !@initial_branch.empty? - safe_system "git", "checkout", "--force", "-B", @upstream_branch, "origin/#{@upstream_branch}", *@quiet_args + # Recreate and check out `#{upstream_branch}` if unable to fast-forward + # it to `origin/#{@upstream_branch}`. Otherwise, just check it out. + if system("git", "merge-base", "--is-ancestor", @upstream_branch, "origin/#{@upstream_branch}") + safe_system "git", "checkout", "--force", @upstream_branch, *@quiet_args + else + safe_system "git", "checkout", "--force", "-B", @upstream_branch, "origin/#{@upstream_branch}", *@quiet_args + end end @initial_revision = read_current_revision |
