diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index 28218da84c60d6546607dbb0362b962a5eecc98e..bd31341df913c50a47d596dfa5863cb284e4e62e 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -35,7 +35,7 @@ module Homebrew description: "Automatically reformat and reword commits in the pull request to our "\ "preferred format." switch "--branch-okay", - description: "Do not warn if pulling to a branch besides master (useful for testing)." + description: "Do not warn if pulling to a branch besides the repository default (useful for testing)." switch "--resolve", description: "When a patch fails to apply, leave in progress and allow user to resolve, "\ "instead of aborting." @@ -291,14 +291,6 @@ module Homebrew Utils::Git.cherry_pick!(path, "--ff", "--allow-empty", *commits, verbose: args.verbose?, resolve: args.resolve?) end - def check_branch(path, ref, args:) - branch = Utils.popen_read("git", "-C", path, "symbolic-ref", "--short", "HEAD").strip - - return if branch == ref || args.clean? || args.branch_okay? - - opoo "Current branch is #{branch}: do you need to pull inside #{ref}?" - end - def formulae_need_bottles?(tap, original_commit, args:) return if args.dry_run? @@ -383,7 +375,12 @@ module Homebrew _, user, repo, pr = *url_match odie "Not a GitHub pull request: #{arg}" unless pr - check_branch tap.path, "master", args: args + current_branch = Utils::Git.current_branch(tap.path) + origin_branch = Utils::Git.origin_branch(tap.path).split("/").last + + if current_branch != origin_branch || args.branch_okay? || args.clean? + opoo "Current branch is #{current_branch}: do you need to pull inside #{origin_branch}?" + end ohai "Fetching #{tap} pull request ##{pr}" Dir.mktmpdir pr do |dir| diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 168c9ce439d67fb8be1b5249e87d2ca89266ffa2..f6567a0f4b9acf546a43ad4b4b9b957a37d568fc 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -120,6 +120,10 @@ module Utils "refs/remotes/origin/HEAD").chomp.presence end + def current_branch(repo) + Utils.popen_read("git", "-C", repo, "symbolic-ref", "--short", "HEAD").chomp.presence + end + # Special case of `git cherry-pick` that permits non-verbose output and # optional resolution on merge conflict. def cherry_pick!(repo, *args, resolve: false, verbose: false) diff --git a/docs/Manpage.md b/docs/Manpage.md index 886e30c8d1957a3b02cf6bac2e8221865fa94015..22b800a20f8610c7a14516ace000cd89597ed28e 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1101,7 +1101,7 @@ Requires write access to the repository. * `--autosquash`: Automatically reformat and reword commits in the pull request to our preferred format. * `--branch-okay`: - Do not warn if pulling to a branch besides master (useful for testing). + Do not warn if pulling to a branch besides the repository default (useful for testing). * `--resolve`: When a patch fails to apply, leave in progress and allow user to resolve, instead of aborting. * `--warn-on-upload-failure`: diff --git a/manpages/brew.1 b/manpages/brew.1 index 98889a0434f3616b95cb9591d95174d5021d8907..d1cc2569c84078d775c24c0e178199fcdbbafa91 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1528,7 +1528,7 @@ Automatically reformat and reword commits in the pull request to our preferred f . .TP \fB\-\-branch\-okay\fR -Do not warn if pulling to a branch besides master (useful for testing)\. +Do not warn if pulling to a branch besides the repository default (useful for testing)\. . .TP \fB\-\-resolve\fR