@@ -33,9 +33,7 @@ protected function getCloneUrl()
33
33
*/
34
34
public function createWorkingCopy (Builder $ builder , $ buildPath )
35
35
{
36
- $ key = trim ($ this ->getProject ()->getSshPrivateKey ());
37
-
38
- if (!empty ($ key )) {
36
+ if ($ this ->canRunSsh ()) {
39
37
$ success = $ this ->cloneBySsh ($ builder , $ buildPath );
40
38
} else {
41
39
$ success = $ this ->cloneByHttp ($ builder , $ buildPath );
@@ -77,32 +75,42 @@ protected function cloneByHttp(Builder $builder, $cloneTo)
77
75
*/
78
76
protected function cloneBySsh (Builder $ builder , $ cloneTo )
79
77
{
80
- $ keyFile = $ this ->writeSshKey ($ cloneTo );
81
-
82
- if (!IS_WIN ) {
83
- $ gitSshWrapper = $ this ->writeSshWrapper ($ cloneTo , $ keyFile );
84
- }
85
-
86
78
// Do the git clone:
87
- $ cmd = 'git clone --recursive ' ;
88
-
79
+ $ cmd = 'git clone --recursive ' ;
89
80
$ depth = $ builder ->getConfig ('clone_depth ' );
90
-
91
81
if (!is_null ($ depth )) {
92
82
$ cmd .= ' --depth ' . intval ($ depth ) . ' ' ;
93
83
}
94
84
95
85
$ cmd .= ' -b %s %s "%s" ' ;
96
86
87
+ $ success = $ this ->runBySsh ($ builder , $ cloneTo , $ cmd , [$ this ->getBranch (), $ this ->getCloneUrl (), $ cloneTo ]);
88
+
89
+ if ($ success ) {
90
+ $ success = $ this ->postCloneSetup ($ builder , $ cloneTo );
91
+ }
92
+
93
+ return $ success ;
94
+ }
95
+
96
+ protected function canRunSsh () {
97
+ $ key = trim ($ this ->getProject ()->getSshPrivateKey ());
98
+ return !empty ($ key );
99
+ }
100
+
101
+ protected function runBySsh (Builder $ builder , $ cloneTo , $ runCommand , $ runArguments ) {
102
+ $ keyFile = $ this ->writeSshKey ($ cloneTo );
103
+
104
+ $ cmd = $ runCommand ;
105
+
97
106
if (!IS_WIN ) {
107
+ $ gitSshWrapper = $ this ->writeSshWrapper ($ cloneTo , $ keyFile );
98
108
$ cmd = 'export GIT_SSH=" ' .$ gitSshWrapper .'" && ' . $ cmd ;
99
109
}
100
110
101
- $ success = $ builder -> executeCommand ( $ cmd , $ this -> getBranch (), $ this -> getCloneUrl (), $ cloneTo );
111
+ array_unshift ( $ runArguments , $ cmd );
102
112
103
- if ($ success ) {
104
- $ success = $ this ->postCloneSetup ($ builder , $ cloneTo );
105
- }
113
+ $ success = call_user_func_array ([$ builder , 'executeCommand ' ], $ runArguments );
106
114
107
115
// Remove the key file and git wrapper:
108
116
unlink ($ keyFile );
0 commit comments