From a8b030ee25e1c623e998548f9f51cdaba3c2476d Mon Sep 17 00:00:00 2001 From: Igor Makarov Date: Sat, 19 Sep 2020 15:08:07 +0300 Subject: [PATCH] support sparse checkout --- lib/cocoapods-core/source.rb | 47 +++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/cocoapods-core/source.rb b/lib/cocoapods-core/source.rb index d33087b6f..7904d4d7f 100644 --- a/lib/cocoapods-core/source.rb +++ b/lib/cocoapods-core/source.rb @@ -111,7 +111,9 @@ def specs_dir # stored. # def pod_path(name) - specs_dir.join(*metadata.path_fragment(name)) + path = specs_dir.join(*metadata.path_fragment(name)) + add_to_sparse_checkout(path) if sparse_checkout? + path end # @return [Pathname] The path at which source metadata is stored. @@ -471,6 +473,49 @@ def unchanged_github_repo? !GitHub.modified_since_commit(url, git_commit_hash) end + # @!group Sparse repo + #-------------------------------------------------------------------------# + + def sparse_checkout_config_path + repo.join('.git/info/sparse-checkout') + end + + def sparse_checkout? + if @is_sparse_checkout.nil? + @is_sparse_checkout = File.exist?(sparse_checkout_config_path) + end + @is_sparse_checkout + end + + def sparse_checkout_patterns + @sparse_checkout_patterns ||= File.read(sparse_checkout_config_path).each_line.map(&:chomp).to_a if sparse_checkout? + end + + def add_to_sparse_checkout(path) + relative_pod_path = path.relative_path_from(repo) + + unless sparse_checkout_patterns.include?(relative_pod_path.to_s) + debug "Adding `#{relative_pod_path}` to sparse checkout file" + File.open(sparse_checkout_config_path, 'a') do |sparse| + sparse.puts relative_pod_path + end + @sparse_checkout_patterns = nil + end + + repo_git(['checkout']) unless Dir.exist?(path) + end + + # @!group Debugging + #-------------------------------------------------------------------------# + + def debug(message) + if defined?(Pod::UI) + Pod::UI.message(message) + else + CoreUI.puts(message) + end + end + #-------------------------------------------------------------------------# end end