Commit 3db7b04c authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Up : La commande oscar.php infos affiche les erreurs liées à GIT

parent 7b672727
Loading
Loading
Loading
Loading
+42 −11
Original line number Diff line number Diff line
@@ -32,19 +32,49 @@ class OscarInfosCommand extends OscarCommandAbstract
    {
        $this->addOutputStyle($output);
        $io = new SymfonyStyle($input, $output);
        $commitHash = trim(exec('git log -1 --pretty="%h" -n1 HEAD'));
        $branch = trim(exec('git branch | grep \* | cut -d \' \' -f2'));

        $commitDate = new \DateTime(trim(exec('git log -n1 --pretty=%ci HEAD')));


        exec('git log -1 --pretty="%h" -n1 HEAD', $commitHash, $gitCommitHashCode);
        if( $gitCommitHashCode > 0 ){
            $io->error("Impossible de charger le HASH GIT");
            $commitHash = "ERROR";
        } else {
            $commitHash = $commitHash[0];
        }

        exec('git symbolic-ref HEAD --short', $branch, $gitBranchCode);
        if( $gitBranchCode > 0 ){
            $io->error("Impossible de charger la branche GIT");
            $branch = "unknow";
        } else {
            $branch = $branch[0];
        }

        exec('git log -n1 --pretty=%ci HEAD', $commitDate, $commitDateCode);
        if( $commitDateCode > 0 ){
            $io->error("Impossible de charger la la date du dernier commit");
            $commitDate = "no date";
        } else {
            $commitDate = new \DateTime(trim($commitDate[0]));
            $commitDate->setTimezone(new \DateTimeZone('UTC'));
            $commitDate = $commitDate->format("Y-m-d H:i:s");
        }

        $split = "¤¤~" . uniqid() . "~¤¤";
        exec(
            "git log --date=iso-local --pretty=format:'$split%H$split%an$split%ad$split%s'",
            $logs
        );
        exec("git log --date=iso-local --pretty=format:'$split%H$split%an$split%ad$split%s'",$logs, $logsCode );
        if( $logsCode > 0 ){
            $io->error("Impossible de charger les logs");
            $logs = [];
        }

        $tag = trim(exec("git tag --points-at HEAD"));
        exec("git tag --points-at HEAD", $tag, $tagCode);
        if( $tagCode > 0 ){
            $io->error("Impossible de charger le tag");
            $tag = "ERROR";
        } else {
            $tag = count($tag)?$tag[0]:"no-tag";
        }

        $infos = [
            "app"        => "Oscar",
@@ -52,7 +82,7 @@ class OscarInfosCommand extends OscarCommandAbstract
            "version"    => OscarVersion::MAJOR . "." . OscarVersion::MINOR . "." . OscarVersion::PATCH,
            "branch"     => $branch,
            "tag"        => $tag,
            "dateUpdate" => $commitDate->format("Y-m-d H:i:s"),
            "dateUpdate" => $commitDate,
            "commitHash" => $commitHash,
            "logs"       => []
        ];
@@ -78,7 +108,8 @@ class OscarInfosCommand extends OscarCommandAbstract
        if ($input->getOption('stdout')) {
            $io->title(sprintf("%s (%s v%s)", $infos['app'], $infos['name'], $infos['version']));
            $io->writeln("branch: <bold>" . $infos['branch'] . "</bold>");
            $io->writeln("Dernier commi: <bold>" . $infos['commitHash'] . "</bold>");
            $io->writeln("Dernier commit: <bold>" . $infos['commitHash'] . "</bold>");
            $io->writeln("Tag: <bold>" . $infos['tag'] . "</bold>");
            $io->writeln("Date: <bold>" . $infos['dateUpdate'] . "</bold>");

            if ($cap > 0) {