Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion lib/cocoapods-core/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels very weird to me that simply querying for the path would have side effects

Copy link
Copy Markdown
Contributor Author

@igor-makarov igor-makarov Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it helps to view it as a "lazy" repo - the code simply ensures that the path can be queried correctly.
If viewed this way, it's not a "side effect" but a necessary implementation detail.

Another way to do this is to add the call to #add_to_sparse_checkout everywhere the path is being queried, but that increases the risk of bugs. My proposition seems more robust to me.

path
end

# @return [Pathname] The path at which source metadata is stored.
Expand Down Expand Up @@ -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