@@ -86,6 +86,11 @@ class Repository
86
86
*/
87
87
protected $ environmentVariables ;
88
88
89
+ /**
90
+ * @var bool
91
+ */
92
+ protected $ inheritEnvironmentVariables ;
93
+
89
94
/**
90
95
* Timeout that should be set for every running process.
91
96
*
@@ -113,14 +118,14 @@ class Repository
113
118
*/
114
119
public function __construct ($ dir , $ options = [])
115
120
{
116
- $ is_windows = defined ('PHP_WINDOWS_VERSION_BUILD ' );
117
121
$ options = array_merge ([
118
- 'working_dir ' => null ,
119
- 'debug ' => true ,
120
- 'logger ' => null ,
121
- 'environment_variables ' => $ is_windows ? ['PATH ' => getenv ('path ' )] : [],
122
- 'command ' => 'git ' ,
123
- 'process_timeout ' => 3600 ,
122
+ 'working_dir ' => null ,
123
+ 'debug ' => true ,
124
+ 'logger ' => null ,
125
+ 'command ' => 'git ' ,
126
+ 'environment_variables ' => [],
127
+ 'inherit_environment_variables ' => false ,
128
+ 'process_timeout ' => 3600 ,
124
129
], $ options );
125
130
126
131
if (null !== $ options ['logger ' ] && !$ options ['logger ' ] instanceof LoggerInterface) {
@@ -131,10 +136,16 @@ public function __construct($dir, $options = [])
131
136
$ this ->initDir ($ dir , $ options ['working_dir ' ]);
132
137
133
138
$ this ->objects = [];
139
+ $ this ->command = $ options ['command ' ];
134
140
$ this ->debug = (bool ) $ options ['debug ' ];
135
- $ this ->environmentVariables = $ options ['environment_variables ' ];
136
141
$ this ->processTimeout = $ options ['process_timeout ' ];
137
- $ this ->command = $ options ['command ' ];
142
+
143
+ if (defined ('PHP_WINDOWS_VERSION_BUILD ' ) && isset ($ _SERVER ['PATH ' ]) && !isset ($ options ['environment_variables ' ]['PATH ' ])) {
144
+ $ options ['environment_variables ' ]['PATH ' ] = $ _SERVER ['PATH ' ];
145
+ }
146
+
147
+ $ this ->environmentVariables = $ options ['environment_variables ' ];
148
+ $ this ->inheritEnvironmentVariables = $ options ['inherit_environment_variables ' ];
138
149
139
150
if (true === $ this ->debug && null !== $ this ->logger ) {
140
151
$ this ->logger ->debug (sprintf ('Repository created (git dir: "%s", working dir: "%s") ' , $ this ->gitDir , $ this ->workingDir ?: 'none ' ));
@@ -620,7 +631,13 @@ private function getProcess($command, $args = [])
620
631
$ base [] = $ command ;
621
632
622
633
$ process = new Process (array_merge ($ base , $ args ));
623
- $ process ->setEnv ($ this ->environmentVariables );
634
+
635
+ if ($ this ->inheritEnvironmentVariables ) {
636
+ $ process ->setEnv (array_replace ($ _SERVER , $ this ->environmentVariables ));
637
+ } else {
638
+ $ process ->setEnv ($ this ->environmentVariables );
639
+ }
640
+
624
641
$ process ->setTimeout ($ this ->processTimeout );
625
642
$ process ->setIdleTimeout ($ this ->processTimeout );
626
643
0 commit comments