1
0
Fork 0

Fix handling of COMPOSER_DISCARD_CHANGES env var

pull/1807/head
Jordi Boggiano 2013-04-15 19:19:27 +02:00
parent 313b79ee13
commit 1d5e3c5a0d
1 changed files with 16 additions and 2 deletions

View File

@ -177,9 +177,23 @@ class Config
return rtrim($this->process($this->config[$key]), '/\\'); return rtrim($this->process($this->config[$key]), '/\\');
case 'discard-changes': case 'discard-changes':
if (!in_array(getenv('COMPOSER_DISCARD_CHANGES') ?: $this->config[$key], array(true, false, 'stash'), true)) { if ($env = getenv('COMPOSER_DISCARD_CHANGES')) {
if (!in_array($env, array('stash', 'true', 'false', '1', '0'), true)) {
throw new \RuntimeException(
"Invalid value for 'discard-changes': {$this->config[$key]}, expected 1, 0, true, false or stash"
);
}
if ('stash' === $env) {
return 'stash';
}
// convert string value to bool
return $env !== 'false' && (bool) $env;
}
if (!in_array($this->config[$key], array(true, false, 'stash'), true)) {
throw new \RuntimeException( throw new \RuntimeException(
"Invalid value for 'discard-changes': {$this->config[$key]}" "Invalid value for 'discard-changes': {$this->config[$key]}, expected true, false or stash"
); );
} }