@@ -3,15 +3,7 @@ module Shards
3
3
4
4
class GitResolver < Resolver
5
5
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)
15
7
update_local_cache
16
8
17
9
if file_exists?(refs, SPEC_FILENAME )
@@ -36,6 +28,17 @@ module Shards
36
28
end
37
29
end
38
30
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
+
39
42
def local_path
40
43
File .join(CACHE_DIRECTORY , dependency.name)
41
44
end
@@ -44,6 +47,17 @@ module Shards
44
47
dependency[" git" ].to_s
45
48
end
46
49
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
+
47
61
private def update_local_cache
48
62
return if @updated_cache
49
63
Shards .logger.info " Updating #{ git_url } "
@@ -58,7 +72,7 @@ module Shards
58
72
end
59
73
60
74
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 } " ,
62
76
path: File .dirname(local_path)
63
77
rescue Error
64
78
raise Error .new(" Failed to clone #{ git_url } " )
0 commit comments