@@ -25,16 +25,15 @@ class Admin
25
25
/**
26
26
* Initializes a repository and returns the instance.
27
27
*
28
- * @param string $path path to the repository
29
- * @param boolean $bare indicate to create a bare repository
30
- * @param boolean $debug flag indicating if errors should be thrown
31
- * @param LoggerInterface $logger logger for debug purposes
28
+ * @param string $path path to the repository
29
+ * @param boolean $bare indicate to create a bare repository
30
+ * @param array $options options for Repository creation
32
31
*
33
32
* @return Repository
34
33
*
35
34
* @throws RuntimeException Directory exists or not writable (only if debug=true)
36
35
*/
37
- public static function init ($ path , $ bare = true , $ debug = true , LoggerInterface $ logger = null )
36
+ public static function init ($ path , $ bare = true , array $ options = array () )
38
37
{
39
38
$ builder = ProcessBuilder::create (array ('git ' , 'init ' , '-q ' ));
40
39
@@ -44,90 +43,82 @@ public static function init($path, $bare = true, $debug = true, LoggerInterface
44
43
45
44
$ builder ->add ($ path );
46
45
46
+ $ builder ->inheritEnvironmentVariables (false );
47
47
$ process = $ builder ->getProcess ();
48
+ if (isset ($ options ['environment_variables ' ])) {
49
+ $ process ->setEnv ($ options ['environment_variables ' ]);
50
+ }
48
51
$ process ->run ();
49
52
50
53
if (!$ process ->isSuccessFul ()) {
51
- $ message = sprintf ("Error on repository initialization, command wasn't successful (%s). Error output: \n%s " , $ process ->getCommandLine (), $ process ->getErrorOutput ());
52
-
53
- if (null !== $ logger ) {
54
- $ logger ->error ($ message );
55
- }
56
-
57
- if (true === $ debug ) {
58
- throw new \RuntimeException ($ message );
59
- }
54
+ throw new \RuntimeException (sprintf ("Error on repository initialization, command wasn't successful (%s). Error output: \n%s " , $ process ->getCommandLine (), $ process ->getErrorOutput ()));
60
55
}
61
56
62
- return new Repository ($ path , $ debug , $ logger );
57
+ return new Repository ($ path , $ options );
63
58
}
64
59
65
60
/**
66
61
* Clone a repository to a local path.
67
62
*
68
- * @param string $path indicates where to clone repository
69
- * @param string $url url of repository to clone
70
- * @param boolean $bare indicates if repository should be bare or have a working copy
71
- * @param boolean $debug flag indicating if errors should be thrown
72
- * @param LoggerInterface $logger logger for debug purpopses
63
+ * @param string $path indicates where to clone repository
64
+ * @param string $url url of repository to clone
65
+ * @param boolean $bare indicates if repository should be bare or have a working copy
66
+ * @param array $options options for Repository creation
73
67
*
74
68
* @return Repository
75
69
*/
76
- public static function cloneTo ($ path , $ url , $ bare = true , $ debug = true , LoggerInterface $ logger = null )
70
+ public static function cloneTo ($ path , $ url , $ bare = true , array $ options = array () )
77
71
{
78
- $ options = array ();
79
-
80
- if ($ bare ) {
81
- $ options [] = '--bare ' ;
82
- }
72
+ $ args = $ bare ? array ('--bare ' ) : array ();
83
73
84
- return static ::cloneRepository ($ path , $ url , $ options , $ debug , $ logger );
74
+ return static ::cloneRepository ($ path , $ url , $ args , $ options );
85
75
}
86
76
87
77
/**
88
78
* Mirrors a repository (fetch all revisions, not only branches).
89
79
*
90
- * @param string $path indicates where to clone repository
91
- * @param string $url url of repository to clone
92
- * @param boolean $debug flag indicating if errors should be thrown
93
- * @param LoggerInterface $logger logger for debug purpopses
80
+ * @param string $path indicates where to clone repository
81
+ * @param string $url url of repository to clone
82
+ * @param array $options options for Repository creation
94
83
*
95
84
* @return Repository
96
85
*/
97
- public static function mirrorTo ($ path , $ url , $ debug = true , LoggerInterface $ logger = null )
86
+ public static function mirrorTo ($ path , $ url , array $ options = array () )
98
87
{
99
- return static ::cloneRepository ($ path , $ url , array ('--mirror ' ), $ logger );
88
+ return static ::cloneRepository ($ path , $ url , array ('--mirror ' ), $ options );
100
89
}
101
90
102
91
/**
103
92
* Internal method to launch effective ``git clone`` command.
104
93
*
105
- * @param string $path indicates where to clone repository
106
- * @param string $url url of repository to clone
107
- * @param array $options arguments to be added to the command-line
108
- * @param boolean $debug flag indicating if errors should be thrown
109
- * @param LoggerInterface $logger logger for debug purpopses
94
+ * @param string $path indicates where to clone repository
95
+ * @param string $url url of repository to clone
96
+ * @param array $args arguments to be added to the command-line
97
+ * @param array $options options for Repository creation
110
98
*
111
99
* @return Repository
112
100
*/
113
- private static function cloneRepository ($ path , $ url , array $ options = array (), $ debug = true , LoggerInterface $ logger = null )
101
+ private static function cloneRepository ($ path , $ url , array $ args = array (), array $ options = array () )
114
102
{
115
103
$ builder = ProcessBuilder::create (array ('git ' , 'clone ' , '-q ' ));
116
-
117
- foreach ($ options as $ value ) {
104
+ foreach ($ args as $ value ) {
118
105
$ builder ->add ($ value );
119
106
}
120
-
121
107
$ builder ->add ($ url );
122
108
$ builder ->add ($ path );
123
109
110
+ $ builder ->inheritEnvironmentVariables (false );
111
+ if (isset ($ options ['environment_variables ' ])) {
112
+ $ builder ->setEnv ($ options ['environment_variables ' ]);
113
+ }
114
+
124
115
$ process = $ builder ->getProcess ();
125
116
$ process ->run ();
126
117
127
118
if (!$ process ->isSuccessFul ()) {
128
119
throw new \RuntimeException (sprintf ('Error while initializing repository: %s ' , $ process ->getErrorOutput ()));
129
120
}
130
121
131
- return new Repository ($ path , $ debug , $ logger );
122
+ return new Repository ($ path , $ options );
132
123
}
133
124
}
0 commit comments