Create git_repo attr
This commit is contained in:
parent
a6fbf5f1ac
commit
b90897e280
@ -113,7 +113,7 @@ module Homebrew
|
||||
end
|
||||
destination_tap.install unless destination_tap.installed?
|
||||
|
||||
repo = source_tap.git_repo.pathname
|
||||
repo = source_tap.path
|
||||
pattern = if source_tap.core_tap?
|
||||
[repo/"Formula/#{name}.rb"]
|
||||
else
|
||||
|
||||
@ -270,14 +270,14 @@ module Homebrew
|
||||
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.
|
||||
reword_package_commit(commit, files.first, git_repo: tap.git_repo, reason: reason, verbose: verbose,
|
||||
resolve: resolve)
|
||||
resolve: resolve)
|
||||
processed_commits << commit
|
||||
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.
|
||||
file = files.first
|
||||
commits = files_to_commits[file]
|
||||
squash_package_commits(commits, file, git_repo: tap.git_repo, reason: reason, verbose: verbose,
|
||||
resolve: resolve)
|
||||
resolve: resolve)
|
||||
processed_commits += commits
|
||||
else
|
||||
# We can't split commits (yet) so just raise an error.
|
||||
@ -483,7 +483,7 @@ resolve: resolve)
|
||||
autosquash!(original_commit, tap: tap, cherry_picked: !args.no_cherry_pick?,
|
||||
verbose: args.verbose?, resolve: args.resolve?, reason: args.message)
|
||||
end
|
||||
signoff!(tap.path, pull_request: pr, dry_run: args.dry_run?) unless args.clean?
|
||||
signoff!(tap.git_repo, pull_request: pr, dry_run: args.dry_run?) unless args.clean?
|
||||
end
|
||||
|
||||
unless formulae_need_bottles?(tap, original_commit, pr_labels, args: args)
|
||||
|
||||
@ -126,7 +126,7 @@ module Homebrew
|
||||
EOS
|
||||
end
|
||||
|
||||
sig { params(repository_path: GitRepoPath, desired_origin: String).returns(T.nilable(String)) }
|
||||
sig { params(repository_path: GitRepository, desired_origin: String).returns(T.nilable(String)) }
|
||||
def examine_git_origin(repository_path, desired_origin)
|
||||
return if !Utils::Git.available? || !repository_path.git_repo?
|
||||
|
||||
@ -156,8 +156,8 @@ module Homebrew
|
||||
def broken_tap(tap)
|
||||
return unless Utils::Git.available?
|
||||
|
||||
repo = HOMEBREW_REPOSITORY.dup.extend(GitRepositoryExtension)
|
||||
return unless repo.git?
|
||||
repo = GitRepository.new(HOMEBREW_REPOSITORY)
|
||||
return unless repo.git_repo?
|
||||
|
||||
message = <<~EOS
|
||||
#{tap.full_name} was not tapped properly! Run:
|
||||
@ -169,7 +169,7 @@ module Homebrew
|
||||
|
||||
tap_head = tap.git_head
|
||||
return message if tap_head.blank?
|
||||
return if tap_head != repo.git_head
|
||||
return if tap_head != repo.head_ref
|
||||
|
||||
message
|
||||
end
|
||||
@ -517,7 +517,7 @@ module Homebrew
|
||||
end
|
||||
|
||||
def check_brew_git_origin
|
||||
repo = HOMEBREW_REPOSITORY.dup.extend(GitRepositoryExtension)
|
||||
repo = GitRepository.new(HOMEBREW_REPOSITORY)
|
||||
examine_git_origin(repo, Homebrew::EnvConfig.brew_git_remote)
|
||||
end
|
||||
|
||||
@ -529,14 +529,14 @@ module Homebrew
|
||||
CoreTap.ensure_installed!
|
||||
end
|
||||
|
||||
broken_tap(coretap) || examine_git_origin(coretap.path, Homebrew::EnvConfig.core_git_remote)
|
||||
broken_tap(coretap) || examine_git_origin(coretap.git_repo, Homebrew::EnvConfig.core_git_remote)
|
||||
end
|
||||
|
||||
def check_casktap_integrity
|
||||
default_cask_tap = Tap.default_cask_tap
|
||||
return unless default_cask_tap.installed?
|
||||
|
||||
broken_tap(default_cask_tap) || examine_git_origin(default_cask_tap.path, default_cask_tap.remote)
|
||||
broken_tap(default_cask_tap) || examine_git_origin(default_cask_tap.git_repo, default_cask_tap.remote)
|
||||
end
|
||||
|
||||
sig { returns(T.nilable(String)) }
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
# typed: strict
|
||||
|
||||
class GitRepoPath < SimpleDelegator
|
||||
include Kernel
|
||||
|
||||
# This is a workaround to enable `alias pathname __getobj__`
|
||||
# @see https://github.com/sorbet/sorbet/issues/2378#issuecomment-569474238
|
||||
sig { returns(Pathname) }
|
||||
def __getobj__; end
|
||||
end
|
||||
@ -7,7 +7,7 @@ require "utils/popen"
|
||||
# Extensions to {Pathname} for querying Git repository information.
|
||||
# @see Utils::Git
|
||||
# @api private
|
||||
class GitRepoPath < SimpleDelegator
|
||||
class GitRepository < SimpleDelegator
|
||||
extend T::Sig
|
||||
|
||||
alias pathname __getobj__
|
||||
@ -1,5 +1,10 @@
|
||||
# typed: strict
|
||||
|
||||
module GitRepositoryExtension
|
||||
requires_ancestor { Pathname }
|
||||
class GitRepository < SimpleDelegator
|
||||
include Kernel
|
||||
|
||||
# This is a workaround to enable `alias pathname __getobj__`
|
||||
# @see https://github.com/sorbet/sorbet/issues/2378#issuecomment-569474238
|
||||
sig { returns(Pathname) }
|
||||
def __getobj__; end
|
||||
end
|
||||
|
||||
@ -131,7 +131,7 @@ end
|
||||
|
||||
require "context"
|
||||
require "extend/array"
|
||||
require "extend/git_repo_path"
|
||||
require "extend/git_repository"
|
||||
require "extend/pathname"
|
||||
require "extend/predicable"
|
||||
require "extend/module"
|
||||
|
||||
@ -32,9 +32,9 @@ module SystemConfig
|
||||
end
|
||||
end
|
||||
|
||||
sig { returns(GitRepoPath) }
|
||||
sig { returns(GitRepository) }
|
||||
def homebrew_repo
|
||||
GitRepoPath.new(HOMEBREW_REPOSITORY)
|
||||
GitRepository.new(HOMEBREW_REPOSITORY)
|
||||
end
|
||||
|
||||
sig { returns(String) }
|
||||
|
||||
@ -93,9 +93,12 @@ class Tap
|
||||
|
||||
# The local path to this {Tap}.
|
||||
# e.g. `/usr/local/Library/Taps/user/homebrew-repo`
|
||||
sig { returns(Pathname) }
|
||||
attr_reader :path
|
||||
|
||||
alias git_repo path
|
||||
# The git repository of this {Tap}.
|
||||
sig { returns(GitRepository) }
|
||||
attr_reader :git_repo
|
||||
|
||||
# @private
|
||||
def initialize(user, repo)
|
||||
@ -103,7 +106,8 @@ class Tap
|
||||
@repo = repo
|
||||
@name = "#{@user}/#{@repo}".downcase
|
||||
@full_name = "#{@user}/homebrew-#{@repo}"
|
||||
@path = GitRepoPath.new(TAP_DIRECTORY/@full_name.downcase)
|
||||
@path = TAP_DIRECTORY/@full_name.downcase
|
||||
@git_repo = GitRepository.new(@path)
|
||||
@alias_table = nil
|
||||
@alias_reverse_table = nil
|
||||
end
|
||||
@ -165,7 +169,7 @@ class Tap
|
||||
|
||||
# True if this {Tap} is a Git repository.
|
||||
def git?
|
||||
path.git_repo?
|
||||
git_repo.git_repo?
|
||||
end
|
||||
|
||||
# git branch for this {Tap}.
|
||||
|
||||
@ -113,7 +113,7 @@ describe "brew pr-pull" do
|
||||
File.write(cask_file, cask_version)
|
||||
safe_system Utils::Git.git, "commit", cask_file, "-m", "version", "--author=#{secondary_author}"
|
||||
described_class.autosquash!(original_hash, tap: tap)
|
||||
git_repo = GitRepoPath.new(path)
|
||||
git_repo = GitRepository.new(path)
|
||||
expect(git_repo.commit_message).to include("food 2.0")
|
||||
expect(git_repo.commit_message).to include("Co-authored-by: #{secondary_author}")
|
||||
end
|
||||
@ -129,7 +129,7 @@ describe "brew pr-pull" do
|
||||
safe_system Utils::Git.git, "add", formula_file
|
||||
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
|
||||
end
|
||||
described_class.signoff!(tap.path)
|
||||
described_class.signoff!(tap.git_repo)
|
||||
expect(tap.git_repo.commit_message).to include("Signed-off-by:")
|
||||
|
||||
(path/"Casks").mkpath
|
||||
@ -138,7 +138,7 @@ describe "brew pr-pull" do
|
||||
safe_system Utils::Git.git, "add", cask_file
|
||||
safe_system Utils::Git.git, "commit", "-m", "food 1.0 (new cask)"
|
||||
end
|
||||
described_class.signoff!(tap.path)
|
||||
described_class.signoff!(tap.git_repo)
|
||||
expect(tap.git_repo.commit_message).to include("Signed-off-by:")
|
||||
end
|
||||
end
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
module Utils
|
||||
# Helper functions for querying Git information.
|
||||
#
|
||||
# @see GitRepoPath
|
||||
# @see GitRepository
|
||||
# @api private
|
||||
module Git
|
||||
extend T::Sig
|
||||
|
||||
@ -15,7 +15,7 @@ module Utils
|
||||
def self.git_head(repo = Pathname.pwd, length: nil, safe: true)
|
||||
return git_short_head(repo, length: length) if length.present?
|
||||
|
||||
repo = GitRepoPath.new(Pathname(repo))
|
||||
repo = GitRepository.new(Pathname(repo))
|
||||
repo.head_ref(safe: safe)
|
||||
end
|
||||
|
||||
@ -28,7 +28,7 @@ module Utils
|
||||
).returns(T.nilable(String))
|
||||
}
|
||||
def self.git_short_head(repo = Pathname.pwd, length: nil, safe: true)
|
||||
repo = GitRepoPath.new(Pathname(repo))
|
||||
repo = GitRepository.new(Pathname(repo))
|
||||
repo.short_head_ref(length: length, safe: safe)
|
||||
end
|
||||
|
||||
@ -40,7 +40,7 @@ module Utils
|
||||
).returns(T.nilable(String))
|
||||
}
|
||||
def self.git_branch(repo = Pathname.pwd, safe: true)
|
||||
repo = GitRepoPath.new(Pathname(repo))
|
||||
repo = GitRepository.new(Pathname(repo))
|
||||
repo.branch_name(safe: safe)
|
||||
end
|
||||
|
||||
@ -53,7 +53,7 @@ module Utils
|
||||
).returns(T.nilable(String))
|
||||
}
|
||||
def self.git_commit_message(repo = Pathname.pwd, commit: "HEAD", safe: true)
|
||||
repo = GitRepoPath.new(Pathname(repo))
|
||||
repo = GitRepository.new(Pathname(repo))
|
||||
repo.commit_message(commit, safe: safe)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user