Merge pull request #12944 from Bo98/pr-pull-formula-dir
dev-cmd/pr-pull: consider alternative tap formula directories
This commit is contained in:
commit
0afd0d774a
@ -209,22 +209,21 @@ module Homebrew
|
|||||||
ohai bump_subject
|
ohai bump_subject
|
||||||
end
|
end
|
||||||
|
|
||||||
def autosquash!(original_commit, path: ".", reason: "", verbose: false, resolve: false)
|
def autosquash!(original_commit, tap:, reason: "", verbose: false, resolve: false)
|
||||||
path = Pathname(path).extend(GitRepositoryExtension)
|
original_head = tap.path.git_head
|
||||||
original_head = path.git_head
|
|
||||||
|
|
||||||
commits = Utils.safe_popen_read("git", "-C", path, "rev-list",
|
commits = Utils.safe_popen_read("git", "-C", tap.path, "rev-list",
|
||||||
"--reverse", "#{original_commit}..HEAD").lines.map(&:strip)
|
"--reverse", "#{original_commit}..HEAD").lines.map(&:strip)
|
||||||
|
|
||||||
# Generate a bidirectional mapping of commits <=> formula files.
|
# Generate a bidirectional mapping of commits <=> formula files.
|
||||||
files_to_commits = {}
|
files_to_commits = {}
|
||||||
commits_to_files = commits.to_h do |commit|
|
commits_to_files = commits.to_h do |commit|
|
||||||
files = Utils.safe_popen_read("git", "-C", path, "diff-tree", "--diff-filter=AMD",
|
files = Utils.safe_popen_read("git", "-C", tap.path, "diff-tree", "--diff-filter=AMD",
|
||||||
"-r", "--name-only", "#{commit}^", commit).lines.map(&:strip)
|
"-r", "--name-only", "#{commit}^", commit).lines.map(&:strip)
|
||||||
files.each do |file|
|
files.each do |file|
|
||||||
files_to_commits[file] ||= []
|
files_to_commits[file] ||= []
|
||||||
files_to_commits[file] << commit
|
files_to_commits[file] << commit
|
||||||
next if %r{^Formula/.*\.rb$}.match?(file)
|
next if (tap.path/file).dirname == tap.formula_dir && File.extname(file) == ".rb"
|
||||||
|
|
||||||
odie <<~EOS
|
odie <<~EOS
|
||||||
Autosquash can't squash commits that modify non-formula files.
|
Autosquash can't squash commits that modify non-formula files.
|
||||||
@ -236,7 +235,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Reset to state before cherry-picking.
|
# Reset to state before cherry-picking.
|
||||||
safe_system "git", "-C", path, "reset", "--hard", original_commit
|
safe_system "git", "-C", tap.path, "reset", "--hard", original_commit
|
||||||
|
|
||||||
# Iterate over every commit in the pull request series, but if we have to squash
|
# Iterate over every commit in the pull request series, but if we have to squash
|
||||||
# multiple commits into one, ensure that we skip over commits we've already squashed.
|
# multiple commits into one, ensure that we skip over commits we've already squashed.
|
||||||
@ -247,13 +246,13 @@ module Homebrew
|
|||||||
files = commits_to_files[commit]
|
files = commits_to_files[commit]
|
||||||
if files.length == 1 && files_to_commits[files.first].length == 1
|
if files.length == 1 && files_to_commits[files.first].length == 1
|
||||||
# If there's a 1:1 mapping of commits to files, just cherry pick and (maybe) reword.
|
# If there's a 1:1 mapping of commits to files, just cherry pick and (maybe) reword.
|
||||||
reword_formula_commit(commit, files.first, path: path, reason: reason, verbose: verbose, resolve: resolve)
|
reword_formula_commit(commit, files.first, path: tap.path, reason: reason, verbose: verbose, resolve: resolve)
|
||||||
processed_commits << commit
|
processed_commits << commit
|
||||||
elsif files.length == 1 && files_to_commits[files.first].length > 1
|
elsif files.length == 1 && files_to_commits[files.first].length > 1
|
||||||
# If multiple commits modify a single file, squash them down into a single commit.
|
# If multiple commits modify a single file, squash them down into a single commit.
|
||||||
file = files.first
|
file = files.first
|
||||||
commits = files_to_commits[file]
|
commits = files_to_commits[file]
|
||||||
squash_formula_commits(commits, file, path: path, reason: reason, verbose: verbose, resolve: resolve)
|
squash_formula_commits(commits, file, path: tap.path, reason: reason, verbose: verbose, resolve: resolve)
|
||||||
processed_commits += commits
|
processed_commits += commits
|
||||||
else
|
else
|
||||||
# We can't split commits (yet) so just raise an error.
|
# We can't split commits (yet) so just raise an error.
|
||||||
@ -266,8 +265,8 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
opoo "Autosquash encountered an error; resetting to original cherry-picked state at #{original_head}"
|
opoo "Autosquash encountered an error; resetting to original cherry-picked state at #{original_head}"
|
||||||
system "git", "-C", path, "reset", "--hard", original_head
|
system "git", "-C", tap.path, "reset", "--hard", original_head
|
||||||
system "git", "-C", path, "cherry-pick", "--abort"
|
system "git", "-C", tap.path, "cherry-pick", "--abort"
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -367,7 +366,7 @@ module Homebrew
|
|||||||
unless args.no_commit?
|
unless args.no_commit?
|
||||||
cherry_pick_pr!(user, repo, pr, path: tap.path, args: args)
|
cherry_pick_pr!(user, repo, pr, path: tap.path, args: args)
|
||||||
if !args.no_autosquash? && !args.dry_run?
|
if !args.no_autosquash? && !args.dry_run?
|
||||||
autosquash!(original_commit, path: tap.path,
|
autosquash!(original_commit, tap: tap,
|
||||||
verbose: args.verbose?, resolve: args.resolve?, reason: args.message)
|
verbose: args.verbose?, resolve: args.resolve?, reason: args.message)
|
||||||
end
|
end
|
||||||
signoff!(tap.path, pr: pr, dry_run: args.dry_run?) unless args.clean?
|
signoff!(tap.path, pr: pr, dry_run: args.dry_run?) unless args.clean?
|
||||||
|
|||||||
@ -40,15 +40,15 @@ describe "brew pr-pull" do
|
|||||||
end
|
end
|
||||||
EOS
|
EOS
|
||||||
end
|
end
|
||||||
let(:formula_file) { path/"Formula/foo.rb" }
|
let(:tap) { Tap.fetch("Homebrew", "foo") }
|
||||||
let(:path) { (Tap::TAP_DIRECTORY/"homebrew/homebrew-foo").extend(GitRepositoryExtension) }
|
let(:formula_file) { tap.path/"Formula/foo.rb" }
|
||||||
|
|
||||||
describe "#autosquash!" do
|
describe "#autosquash!" do
|
||||||
it "squashes a formula correctly" do
|
it "squashes a formula correctly" do
|
||||||
secondary_author = "Someone Else <me@example.com>"
|
secondary_author = "Someone Else <me@example.com>"
|
||||||
(path/"Formula").mkpath
|
(tap.path/"Formula").mkpath
|
||||||
formula_file.write(formula)
|
formula_file.write(formula)
|
||||||
cd path do
|
cd tap.path do
|
||||||
safe_system Utils::Git.git, "init"
|
safe_system Utils::Git.git, "init"
|
||||||
safe_system Utils::Git.git, "add", formula_file
|
safe_system Utils::Git.git, "add", formula_file
|
||||||
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
|
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
|
||||||
@ -57,24 +57,24 @@ describe "brew pr-pull" do
|
|||||||
safe_system Utils::Git.git, "commit", formula_file, "-m", "revision"
|
safe_system Utils::Git.git, "commit", formula_file, "-m", "revision"
|
||||||
File.write(formula_file, formula_version)
|
File.write(formula_file, formula_version)
|
||||||
safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}"
|
safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}"
|
||||||
described_class.autosquash!(original_hash, path: path)
|
described_class.autosquash!(original_hash, tap: tap)
|
||||||
expect(path.git_commit_message).to include("foo 2.0")
|
expect(tap.path.git_commit_message).to include("foo 2.0")
|
||||||
expect(path.git_commit_message).to include("Co-authored-by: #{secondary_author}")
|
expect(tap.path.git_commit_message).to include("Co-authored-by: #{secondary_author}")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#signoff!" do
|
describe "#signoff!" do
|
||||||
it "signs off a formula" do
|
it "signs off a formula" do
|
||||||
(path/"Formula").mkpath
|
(tap.path/"Formula").mkpath
|
||||||
formula_file.write(formula)
|
formula_file.write(formula)
|
||||||
cd path do
|
cd tap.path do
|
||||||
safe_system Utils::Git.git, "init"
|
safe_system Utils::Git.git, "init"
|
||||||
safe_system Utils::Git.git, "add", formula_file
|
safe_system Utils::Git.git, "add", formula_file
|
||||||
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
|
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
|
||||||
end
|
end
|
||||||
described_class.signoff!(path)
|
described_class.signoff!(tap.path)
|
||||||
expect(path.git_commit_message).to include("Signed-off-by:")
|
expect(tap.path.git_commit_message).to include("Signed-off-by:")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user