@@ -7,6 +7,7 @@ import java.nio.file.Files
7
7
import java .util .stream .Collectors
8
8
import com .indoorvivants .detective .Platform
9
9
import Platform .OS ._
10
+ import scala .util .control .NonFatal
10
11
11
12
object VcpkgBootstrap {
12
13
private val REMOTE_URI = " https://github.com/microsoft/vcpkg"
@@ -23,17 +24,32 @@ object VcpkgBootstrap {
23
24
case _ => " vcpkg"
24
25
}
25
26
26
- def clone (directory : File ) = {
27
- import org .eclipse .jgit .api .Git
27
+ private def cloneWithGit (directory : File , log : ExternalLogger ) = {
28
+ val cmd = Seq (
29
+ " git" ,
30
+ " clone" ,
31
+ " --single-branch" ,
32
+ " --recurse-submodules" ,
33
+ REMOTE_URI ,
34
+ directory.toString()
35
+ )
36
+
37
+ sys.process.Process (cmd).! == 0
38
+ }
28
39
29
- val repo = Git
30
- .cloneRepository()
31
- .setURI(REMOTE_URI )
32
- .setDirectory(directory)
33
- .setBranchesToClone(Arrays .asList(" refs/heads/master" ))
34
- .setCloneAllBranches(false )
35
- .setCloneSubmodules(true )
36
- .call()
40
+ def clone (directory : File , log : ExternalLogger ) = {
41
+ if (! gitAvailable(log) || ! cloneWithGit(directory, log)) {
42
+ import org .eclipse .jgit .api .Git
43
+
44
+ val repo = Git
45
+ .cloneRepository()
46
+ .setURI(REMOTE_URI )
47
+ .setDirectory(directory)
48
+ .setBranchesToClone(Arrays .asList(" refs/heads/master" ))
49
+ .setCloneAllBranches(false )
50
+ .setCloneSubmodules(true )
51
+ .call()
52
+ }
37
53
38
54
}
39
55
@@ -73,4 +89,22 @@ object VcpkgBootstrap {
73
89
74
90
new Vcpkg (config, logger)
75
91
}
92
+
93
+ private def gitAvailable (log : ExternalLogger ): Boolean = {
94
+ val cmd = Seq (" git" , " --version" )
95
+
96
+ try {
97
+ val contents = sys.process.Process (cmd).!!
98
+ contents.startsWith(" git version" )
99
+ } catch {
100
+ case NonFatal (_) =>
101
+ log.warn(
102
+ " `git` command is not available, falling back to JGit which is slower"
103
+ )
104
+
105
+ false
106
+
107
+ }
108
+
109
+ }
76
110
}
0 commit comments