From 2cd207618688f247c28378386e88fc23945c100d Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Fri, 9 Jun 2023 22:58:00 -0400 Subject: [PATCH 1/3] Use "cone" mode for sparse checkouts --- Library/Homebrew/download_strategy.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 8a0edae687..04d8b95883 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -1075,9 +1075,17 @@ class GitDownloadStrategy < VCSDownloadStrategy command! "git", args: ["config", "core.sparseCheckout", "true"], chdir: cached_location + command! "git", + args: ["config", "core.sparseCheckoutCone", "true"], + chdir: cached_location (git_dir/"info").mkpath - (git_dir/"info"/"sparse-checkout").atomic_write("#{@only_path}\n") + + # "Cone" mode of sparse checkout requires patterns to be directories + path = @only_path + path = "/#{path}" unless path.start_with?("/") + path = "#{path}/" unless path.end_with?("/") + (git_dir/"info"/"sparse-checkout").atomic_write("#{path}\n") end end From 747d3aaaba3d6c2b12e10530b9ffcb2aa916a765 Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Sat, 10 Jun 2023 14:08:05 -0400 Subject: [PATCH 2/3] Apply review suggestions --- Library/Homebrew/download_strategy.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 04d8b95883..a96bd2bbdd 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -835,6 +835,10 @@ class GitDownloadStrategy < VCSDownloadStrategy # constructor calls `cache_tag` and sets the cache path. @only_path = meta[:only_path] + # "Cone" mode of sparse checkout requires patterns to be directories + @only_path = "/#{@only_path}" unless @only_path.start_with?("/") + @only_path = "#{@only_path}/" unless @only_path.end_with?("/") + super @ref_type ||= :branch @ref ||= "master" @@ -1080,12 +1084,7 @@ class GitDownloadStrategy < VCSDownloadStrategy chdir: cached_location (git_dir/"info").mkpath - - # "Cone" mode of sparse checkout requires patterns to be directories - path = @only_path - path = "/#{path}" unless path.start_with?("/") - path = "#{path}/" unless path.end_with?("/") - (git_dir/"info"/"sparse-checkout").atomic_write("#{path}\n") + (git_dir/"info/sparse-checkout").atomic_write("#{@only_path}\n") end end From d2b17e29effebd03612ec1758b806a567fbecb91 Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Sat, 10 Jun 2023 14:31:46 -0400 Subject: [PATCH 3/3] Check `only_path` is present before modifying it --- Library/Homebrew/download_strategy.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index a96bd2bbdd..3a3fcddcb2 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -835,9 +835,11 @@ class GitDownloadStrategy < VCSDownloadStrategy # constructor calls `cache_tag` and sets the cache path. @only_path = meta[:only_path] - # "Cone" mode of sparse checkout requires patterns to be directories - @only_path = "/#{@only_path}" unless @only_path.start_with?("/") - @only_path = "#{@only_path}/" unless @only_path.end_with?("/") + if @only_path.present? + # "Cone" mode of sparse checkout requires patterns to be directories + @only_path = "/#{@only_path}" unless @only_path.start_with?("/") + @only_path = "#{@only_path}/" unless @only_path.end_with?("/") + end super @ref_type ||= :branch