Parcourir la source

Fix handling of COMPOSER_DISCARD_CHANGES env var

Jordi Boggiano il y a 12 ans
Parent
commit
1d5e3c5a0d
1 fichiers modifiés avec 16 ajouts et 2 suppressions
  1. 16 2
      src/Composer/Config.php

+ 16 - 2
src/Composer/Config.php

@@ -177,9 +177,23 @@ class Config
                 return rtrim($this->process($this->config[$key]), '/\\');
 
             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(
-                        "Invalid value for 'discard-changes': {$this->config[$key]}"
+                        "Invalid value for 'discard-changes': {$this->config[$key]}, expected true, false or stash"
                     );
                 }