diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index 4c3317e52c..02e498baec 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -216,7 +216,8 @@ module Homebrew end def autosquash!(original_commit, path: ".", reason: "", verbose: false, resolve: false) - original_head = Utils.safe_popen_read("git", "-C", path, "rev-parse", "HEAD").strip + path = Pathname(path).extend(GitRepositoryExtension) + original_head = path.git_head commits = Utils.safe_popen_read("git", "-C", path, "rev-list", "--reverse", "#{original_commit}..HEAD").lines.map(&:strip) @@ -394,7 +395,7 @@ module Homebrew ohai "Fetching #{tap} pull request ##{pr}" Dir.mktmpdir pr do |dir| cd dir do - original_commit = Utils.popen_read("git", "-C", tap.path, "rev-parse", "HEAD").chomp + original_commit = tap.path.git_head cherry_pick_pr!(user, repo, pr, path: tap.path, args: args) if args.autosquash? && !args.dry_run? autosquash!(original_commit, path: tap.path, diff --git a/Library/Homebrew/test/dev-cmd/pr-pull_spec.rb b/Library/Homebrew/test/dev-cmd/pr-pull_spec.rb index 848323c00f..98a95c4ae6 100644 --- a/Library/Homebrew/test/dev-cmd/pr-pull_spec.rb +++ b/Library/Homebrew/test/dev-cmd/pr-pull_spec.rb @@ -58,7 +58,7 @@ describe Homebrew do safe_system Utils::Git.git, "commit", formula_file, "-m", "revision" File.open(formula_file, "w") { |f| f.write(formula_version) } safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}" - described_class.autosquash!(original_hash, path: ".") + described_class.autosquash!(original_hash, path: path) expect(Utils::Git.commit_message(path)).to include("foo 2.0") expect(Utils::Git.commit_message(path)).to include("Co-authored-by: #{secondary_author}") end