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

Stop using shallow clones #11328

Merged
merged 1 commit into from May 5, 2021
Merged
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
20 changes: 2 additions & 18 deletions Library/Homebrew/download_strategy.rb
Expand Up @@ -776,18 +776,10 @@ def clone_repo(timeout: nil)
#
# @api public
class GitDownloadStrategy < VCSDownloadStrategy
SHALLOW_CLONE_ALLOWLIST = [
%r{git://},
%r{https://github\.com},
%r{http://git\.sv\.gnu\.org},
%r{http://llvm\.org},
].freeze

def initialize(url, name, version, **meta)
super
@ref_type ||= :branch
@ref ||= "master"
@shallow = meta.fetch(:shallow, true)
end

# @see AbstractDownloadStrategy#source_modified_time
Expand Down Expand Up @@ -827,18 +819,10 @@ def update(timeout: nil)
update_submodules(timeout: timeout) if submodules?
end

def shallow_clone?
@shallow && support_depth?
end

def shallow_dir?
(git_dir/"shallow").exist?
end

def support_depth?
@ref_type != :revision && SHALLOW_CLONE_ALLOWLIST.any? { |regex| @url =~ regex }
end

def git_dir
cached_location/".git"
end
Expand All @@ -865,7 +849,6 @@ def submodules?
sig { returns(T::Array[String]) }
def clone_args
args = %w[clone]
args << "--depth" << "1" if shallow_clone?

case @ref_type
when :branch, :tag
Expand Down Expand Up @@ -902,7 +885,8 @@ def config_repo
def update_repo(timeout: nil)
return if @ref_type != :branch && ref?

if !shallow_clone? && shallow_dir?
# Convert any shallow clone to full clone
if shallow_dir?
command! "git",
args: ["fetch", "origin", "--unshallow"],
chdir: cached_location,
Expand Down