@@ -104,6 +104,7 @@ public static function is_repo($var) {
104104class GitRepo {
105105
106106 protected $ repo_path = null ;
107+ protected $ envopts = array ();
107108
108109 /**
109110 * Create a new git repository
@@ -230,7 +231,26 @@ protected function run_command($command) {
230231 2 => array ('pipe ' , 'w ' ),
231232 );
232233 $ pipes = array ();
233- $ resource = proc_open ($ command , $ descriptorspec , $ pipes , $ this ->repo_path );
234+ /* Depending on the value of variables_order, $_ENV may be empty.
235+ * In that case, we have to explicitly set the new variables with
236+ * putenv, and call proc_open with env=null to inherit the reset
237+ * of the system.
238+ *
239+ * This is kind of crappy because we cannot easily restore just those
240+ * variables afterwards.
241+ *
242+ * If $_ENV is not empty, then we can just copy it and be done with it.
243+ */
244+ if (count ($ _ENV ) === 0 ) {
245+ $ env = NULL ;
246+ foreach ($ this ->envopts as $ k => $ v ) {
247+ putenv (sprintf ("%s=%s " ,$ k ,$ v ));
248+ }
249+ } else {
250+ $ env = array_merge ($ _ENV , $ this ->envopts );
251+ }
252+ $ cwd = $ this ->repo_path ;
253+ $ resource = proc_open ($ command , $ descriptorspec , $ pipes , $ cwd , $ env );
234254
235255 $ stdout = stream_get_contents ($ pipes [1 ]);
236256 $ stderr = stream_get_contents ($ pipes [2 ]);
@@ -523,6 +543,16 @@ public function set_description($new) {
523543 public function get_description () {
524544 return file_get_contents ($ this ->repo_path ."/.git/description " );
525545 }
546+
547+ /**
548+ * Sets custom environment options for calling Git
549+ *
550+ * @param string key
551+ * @param string value
552+ */
553+ public function setenv ($ key , $ value ) {
554+ $ this ->envopts [$ key ] = $ value ;
555+ }
526556
527557}
528558
0 commit comments