From a04256810e729d0be6a3d457658f3879e07f6988 Mon Sep 17 00:00:00 2001
From: Jordi Boggiano <j.boggiano@seld.be>
Date: Mon, 12 Sep 2016 11:25:43 +0200
Subject: [PATCH] Change exit code to be 1/2 for warn/fail, refs #5601

---
 src/Composer/Command/DiagnoseCommand.php | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php
index 9dccfced3..44ccfa60b 100644
--- a/src/Composer/Command/DiagnoseCommand.php
+++ b/src/Composer/Command/DiagnoseCommand.php
@@ -40,7 +40,7 @@ class DiagnoseCommand extends BaseCommand
     protected $process;
 
     /** @var int */
-    protected $failures = 0;
+    protected $exitCode = 0;
 
     protected function configure()
     {
@@ -50,6 +50,8 @@ class DiagnoseCommand extends BaseCommand
             ->setHelp(<<<EOT
 The <info>diagnose</info> command checks common errors to help debugging problems.
 
+The process exit code will be 1 in case of warnings and 2 for errors.
+
 EOT
             )
         ;
@@ -147,7 +149,7 @@ EOT
             $this->outputResult($this->checkVersion($config));
         }
 
-        return $this->failures;
+        return $this->exitCode;
     }
 
     private function checkComposerSchema()
@@ -385,12 +387,12 @@ EOT
     private function outputResult($result)
     {
         $io = $this->getIO();
-        $hadError = false;
         if (true === $result) {
             $io->write('<info>OK</info>');
             return;
         }
 
+        $hadError = false;
         if ($result instanceof \Exception) {
             $result = '<error>['.get_class($result).'] '.$result->getMessage().'</error>';
         }
@@ -411,9 +413,10 @@ EOT
 
         if ($hadError) {
             $io->write('<error>FAIL</error>');
-            $this->failures++;
+            $this->exitCode = 2;
         } else {
             $io->write('<warning>WARNING</warning>');
+            $this->exitCode = 1;
         }
 
         if ($result) {