@@ -7,7 +7,7 @@ class Source
77 class Git < Path
88 autoload :GitProxy , File . expand_path ( "git/git_proxy" , __dir__ )
99
10- attr_reader :uri , :ref , :branch , :options , :glob , :submodules
10+ attr_reader :uri , :ref , :branch , :options , :glob , :submodules , :sparse_checkout
1111
1212 def initialize ( options )
1313 @options = options
@@ -25,6 +25,7 @@ def initialize(options)
2525 @branch = options [ "branch" ]
2626 @ref = options [ "ref" ] || options [ "branch" ] || options [ "tag" ]
2727 @submodules = options [ "submodules" ]
28+ @sparse_checkout = options [ "sparse_checkout" ]
2829 @name = options [ "name" ]
2930 @version = options [ "version" ] . to_s . strip . gsub ( "-" , ".pre." )
3031
@@ -57,27 +58,29 @@ def to_lock
5758 %w[ ref branch tag submodules ] . each do |opt |
5859 out << " #{ opt } : #{ options [ opt ] } \n " if options [ opt ]
5960 end
61+ out << " sparse_checkout: #{ @sparse_checkout } \n " if @sparse_checkout
6062 out << " glob: #{ @glob } \n " unless default_glob?
6163 out << " specs:\n "
6264 end
6365
6466 def to_gemfile
65- specifiers = %w[ ref branch tag submodules glob ] . map do |opt |
67+ specifiers = %w[ ref branch tag submodules glob sparse_checkout ] . map do |opt |
6668 "#{ opt } : #{ options [ opt ] } " if options [ opt ]
6769 end
6870
6971 uri_with_specifiers ( specifiers )
7072 end
7173
7274 def hash
73- [ self . class , uri , ref , branch , name , glob , submodules ] . hash
75+ [ self . class , uri , ref , branch , name , glob , submodules , sparse_checkout ] . hash
7476 end
7577
7678 def eql? ( other )
7779 other . is_a? ( Git ) && uri == other . uri && ref == other . ref &&
7880 branch == other . branch && name == other . name &&
7981 glob == other . glob &&
80- submodules == other . submodules
82+ submodules == other . submodules &&
83+ sparse_checkout == other . sparse_checkout
8184 end
8285
8386 alias_method :== , :eql?
@@ -86,7 +89,8 @@ def include?(other)
8689 other . is_a? ( Git ) && uri == other . uri &&
8790 name == other . name &&
8891 glob == other . glob &&
89- submodules == other . submodules
92+ submodules == other . submodules &&
93+ sparse_checkout == other . sparse_checkout
9094 end
9195
9296 def to_s
@@ -126,17 +130,13 @@ def name
126130 # checkout of the git repository. When using local git
127131 # repos, this is set to the local repo.
128132 def install_path
129- @install_path ||= begin
130- git_scope = "#{ base_name } -#{ shortref_for_path ( revision ) } "
131-
132- Bundler . install_path . join ( git_scope )
133- end
133+ @install_path ||= Bundler . install_path . join ( "#{ base_name } -#{ shortref_for_path ( revision , sparse_checkout : @sparse_checkout ) } " )
134134 end
135135
136136 alias_method :path , :install_path
137137
138138 def extension_dir_name
139- "#{ base_name } -#{ shortref_for_path ( revision ) } "
139+ "#{ base_name } -#{ shortref_for_path ( revision , sparse_checkout : @sparse_checkout ) } "
140140 end
141141
142142 def unlock!
@@ -246,7 +246,7 @@ def cache_path
246246 end
247247
248248 def app_cache_dirname
249- "#{ base_name } -#{ shortref_for_path ( locked_revision || revision ) } "
249+ "#{ base_name } -#{ shortref_for_path ( locked_revision || revision , sparse_checkout : @sparse_checkout ) } "
250250 end
251251
252252 def revision
@@ -375,8 +375,10 @@ def shortref_for_display(ref)
375375 ref [ 0 ..6 ]
376376 end
377377
378- def shortref_for_path ( ref )
379- ref [ 0 ..11 ]
378+ def shortref_for_path ( ref , sparse_checkout : nil )
379+ scope = ref [ 0 ..11 ]
380+ scope += "-#{ Bundler ::Digest . sha1 ( sparse_checkout ) [ 0 ..7 ] } " if sparse_checkout
381+ scope
380382 end
381383
382384 def glob_for_display
@@ -432,7 +434,9 @@ def load_gemspec(file)
432434 end
433435
434436 def git_scope
435- "#{ base_name } -#{ uri_hash } "
437+ scope = "#{ base_name } -#{ uri_hash } "
438+ scope += "-#{ Bundler ::Digest . sha1 ( @sparse_checkout ) [ 0 ..7 ] } " if @sparse_checkout
439+ scope
436440 end
437441
438442 def extension_cache_slug ( _ )
0 commit comments