@@ -3,15 +3,7 @@ module Shards
33
44 class GitResolver < Resolver
55 def read_spec (version = " *" )
6- refs = case version
7- when RELEASE_VERSION
8- " v#{ version } "
9- when " *"
10- " HEAD"
11- else
12- version
13- end
14-
6+ refs = git_refs(version)
157 update_local_cache
168
179 if file_exists?(refs, SPEC_FILENAME )
@@ -36,6 +28,17 @@ module Shards
3628 end
3729 end
3830
31+ # OPTIMIZE: don't clean/install if the installed version is the expected one (ie. don't be dumb!)
32+ def install (version = nil )
33+ refs = git_refs(version)
34+ Shards .logger.info " Installing #{ dependency.name } (#{ version } )"
35+
36+ cleanup_install_directory
37+ Dir .mkdir(install_path)
38+
39+ run " git archive --format=tar #{ refs } | tar x -C #{ escape install_path } "
40+ end
41+
3942 def local_path
4043 File .join(CACHE_DIRECTORY , dependency.name)
4144 end
@@ -44,6 +47,17 @@ module Shards
4447 dependency[" git" ].to_s
4548 end
4649
50+ private def git_refs (version )
51+ case version
52+ when RELEASE_VERSION
53+ " v#{ version } "
54+ when " *"
55+ " HEAD"
56+ else
57+ version
58+ end
59+ end
60+
4761 private def update_local_cache
4862 return if @updated_cache
4963 Shards .logger.info " Updating #{ git_url } "
@@ -58,7 +72,7 @@ module Shards
5872 end
5973
6074 private def clone_repository
61- run " git clone --mirror --quiet -- ' #{ git_url.gsub( /'/ , " \\ ' " ) } ' #{ dependency.name } " ,
75+ run " git clone --mirror --quiet -- #{ escape git_url } #{ dependency.name } " ,
6276 path: File .dirname(local_path)
6377 rescue Error
6478 raise Error .new(" Failed to clone #{ git_url } " )
0 commit comments