Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull: cleanup more code. #7403

Merged
merged 1 commit into from Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 8 additions & 47 deletions Library/Homebrew/dev-cmd/pull.rb
Expand Up @@ -8,7 +8,6 @@
require "formulary"
require "version"
require "pkg_version"
require "bottle_publisher"
require "formula_info"

module Homebrew
Expand All @@ -20,7 +19,6 @@ def pull_args
`pull` [<options>] <patch>

Get a patch from a GitHub commit or pull request and apply it to Homebrew.
Optionally, publish updated bottles for any formulae changed by the patch.

Each <patch> may be the number of a pull request in `homebrew/core`
or the URL of any pull request or commit on GitHub.
Expand Down Expand Up @@ -96,26 +94,23 @@ def pull
HOMEBREW_CACHE.mkpath

# Store current revision and branch
merge_commit = merge_commit?(url)
orig_revision = `git rev-parse --short HEAD`.strip
branch = `git symbolic-ref --short HEAD`.strip

if branch != "master" && !args.clean? && !args.branch_okay?
opoo "Current branch is #{branch}: do you need to pull inside master?"
end

unless merge_commit
patch_puller = PatchPuller.new(url, args)
patch_puller.fetch_patch
patch_changes = files_changed_in_patch(patch_puller.patchpath, tap)
patch_puller = PatchPuller.new(url, args)
patch_puller.fetch_patch
patch_changes = files_changed_in_patch(patch_puller.patchpath, tap)

is_bumpable = patch_changes[:formulae].length == 1 && patch_changes[:others].empty?
check_bumps(patch_changes) if do_bump
old_versions = current_versions_from_info_external(patch_changes[:formulae].first) if is_bumpable
patch_puller.apply_patch
end
is_bumpable = patch_changes[:formulae].length == 1 && patch_changes[:others].empty?
check_bumps(patch_changes) if do_bump
old_versions = current_versions_from_info_external(patch_changes[:formulae].first) if is_bumpable
patch_puller.apply_patch

end_revision = head_revision(url, merge_commit)
end_revision = head_revision(url)

changed_formulae_names = []

Expand Down Expand Up @@ -187,8 +182,6 @@ def pull
safe_system "git", "commit", "--amend", "--signoff", "--allow-empty", "-q", "-m", message
end

fetch_merge_patch(url, args, issue) if merge_commit

ohai "Patch changed:"
safe_system "git", "diff-tree", "-r", "--stat", orig_revision, end_revision
end
Expand All @@ -204,22 +197,10 @@ def check_bumps(patch_changes)
end
end

def merge_commit?(url)
pr_number = url[%r{/pull\/([0-9]+)}, 1]
return false unless pr_number

safe_system "git", "fetch", "--quiet", "origin", "pull/#{pr_number}/head"
Utils.popen_read("git", "rev-list", "--parents", "-n1", "FETCH_HEAD").count(" ") > 1
end

def head_revision(_url, fetched)
Utils.popen_read("git", "rev-parse", fetched ? "FETCH_HEAD" : "HEAD").strip
end

def fetch_merge_patch(url, args, issue)
PatchPuller.new(url, args, "merge commit").pull_merge_commit(issue)
end

class PatchPuller
attr_reader :base_url
attr_reader :patch_url
Expand All @@ -234,26 +215,6 @@ def initialize(url, args, description = nil)
@args = args
end

def pull_patch
fetch_patch
apply_patch
end

def pull_merge_commit(issue)
# Used by forks of homebrew-core that use merge-commits (for example linuxbrew)
ohai "Fast-forwarding to the merge commit"
test_bot_origin = patch_url[%r{(https://github\.com/[\w-]+/[\w-]+)/compare/}, 1]
safe_system "git", "fetch", "--quiet", test_bot_origin, "pr-#{issue}" if test_bot_origin
safe_system "git", "merge", "--quiet", "--ff-only", "--no-edit", "FETCH_HEAD"
return if $CHILD_STATUS.success?

safe_system "git", "reset", "--hard", "FETCH_HEAD"
odie <<~EOS
Not possible to fast-forward.
Maybe somebody pushed commits to origin/master between the merge commit creation and now.
EOS
end

def fetch_patch
extra_msg = @description ? "(#{@description})" : nil
ohai "Fetching patch #{extra_msg}"
Expand Down
1 change: 0 additions & 1 deletion docs/Manpage.md
Expand Up @@ -904,7 +904,6 @@ Run Homebrew with the Ruby profiler, e.g. `brew prof readall`.
### `pull` [*`options`*] *`patch`*

Get a patch from a GitHub commit or pull request and apply it to Homebrew.
Optionally, publish updated bottles for any formulae changed by the patch.

Each *`patch`* may be the number of a pull request in `homebrew/core` or the URL
of any pull request or commit on GitHub.
Expand Down
2 changes: 1 addition & 1 deletion manpages/brew.1
Expand Up @@ -1167,7 +1167,7 @@ Target tap repository (default: homebrew/core)\.
Run Homebrew with the Ruby profiler, e\.g\. \fBbrew prof readall\fR\.
.
.SS "\fBpull\fR [\fIoptions\fR] \fIpatch\fR"
Get a patch from a GitHub commit or pull request and apply it to Homebrew\. Optionally, publish updated bottles for any formulae changed by the patch\.
Get a patch from a GitHub commit or pull request and apply it to Homebrew\.
.
.P
Each \fIpatch\fR may be the number of a pull request in \fBhomebrew/core\fR or the URL of any pull request or commit on GitHub\.
Expand Down