@@ -35,21 +35,7 @@ class Admin
3535 */
3636 public static function init ($ path , $ bare = true , array $ options = array ())
3737 {
38- $ command = isset ($ options ['command ' ]) ? $ options ['command ' ] : 'git ' ;
39-
40- // command-line
41- $ builder = ProcessBuilder::create (array ($ command , 'init ' , '-q ' ));
42- if ($ bare ) {
43- $ builder ->add ('--bare ' );
44- }
45- $ builder ->add ($ path );
46-
47- // environment
48- $ builder ->inheritEnvironmentVariables (false );
49- $ process = $ builder ->getProcess ();
50- if (isset ($ options ['environment_variables ' ])) {
51- $ process ->setEnv ($ options ['environment_variables ' ]);
52- }
38+ $ process = static ::getProcess ('init ' , array_merge (array ('-q ' ), $ bare ? array ('--bare ' ) : array (), array ($ path )), $ options );
5339
5440 $ process ->run ();
5541
@@ -74,11 +60,8 @@ public static function init($path, $bare = true, array $options = array())
7460 */
7561 public static function isValidRepository ($ url , array $ options = array ())
7662 {
77- $ command = isset ($ options ['command ' ]) ? $ options ['command ' ] : 'git ' ;
78- $ builder = ProcessBuilder::create (array ($ command , 'ls-remote ' ));
79- $ builder ->add ($ url );
63+ $ process = static ::getProcess ('ls-remote ' , array ($ url ), $ options );
8064
81- $ process = $ builder ->getProcess ();
8265 $ process ->run ();
8366
8467 return $ process ->isSuccessFul ();
@@ -127,19 +110,7 @@ public static function mirrorTo($path, $url, array $options = array())
127110 */
128111 private static function cloneRepository ($ path , $ url , array $ args = array (), array $ options = array ())
129112 {
130- $ command = isset ($ options ['command ' ]) ? $ options ['command ' ] : 'git ' ;
131- $ builder = ProcessBuilder::create (array ($ command , 'clone ' , '-q ' ));
132- foreach ($ args as $ value ) {
133- $ builder ->add ($ value );
134- }
135- $ builder ->add ($ url );
136- $ builder ->add ($ path );
137-
138- $ builder ->inheritEnvironmentVariables (false );
139- $ process = $ builder ->getProcess ();
140- if (isset ($ options ['environment_variables ' ])) {
141- $ process ->setEnv ($ options ['environment_variables ' ]);
142- }
113+ $ process = static ::getProcess ('clone ' , array_merge (array ('-q ' ), $ args , array ($ url , $ path )), $ options );
143114
144115 $ process ->run ();
145116
@@ -149,4 +120,27 @@ private static function cloneRepository($path, $url, array $args = array(), arra
149120
150121 return new Repository ($ path , $ options );
151122 }
123+
124+ /**
125+ * This internal method is used to create a process object.
126+ */
127+ private static function getProcess ($ command , array $ args = array (), array $ options = array ())
128+ {
129+ $ options = array_merge (array (
130+ 'environment_variables ' => array (),
131+ 'command ' => 'git ' ,
132+ 'process_timeout ' => 3600
133+ ), $ options );
134+
135+ $ builder = ProcessBuilder::create (array_merge (array ($ options ['command ' ], $ command ), $ args ));
136+ $ builder ->inheritEnvironmentVariables (false );
137+
138+ $ process = $ builder ->getProcess ();
139+ $ process ->setEnv ($ options ['environment_variables ' ]);
140+ $ process ->setTimeout ($ options ['process_timeout ' ]);
141+ $ process ->setIdleTimeout ($ options ['process_timeout ' ]);
142+
143+ return $ process ;
144+ }
145+
152146}
0 commit comments