Skip to content

Thrown ConsoleException when git command returns nothing #62

@anystar

Description

@anystar

I get a ConsoleException when I run below command.

$git->repo->run("config core.safecrlf false");

And it seems in general I get that exception when I run commands that run successfully however don't return with anything.

My stack trace points to line 100 of Console.php

if ($status) throw new ConsoleException($stderr . PHP_EOL . $stdout);

And honestly that condition looks very sketchy. Shouldn't the conditional statement be checking if $status returns -1? And why are we trimming the return value anyway?

Full function from Command.php below.

    public function runCommand($command)
    {
        $descriptorSpec = array(
            1 => array('pipe', 'w'),
            2 => array('pipe', 'w'),
        );
        $pipes = array();
        /**
         * Depending on the value of variables_order, $_ENV may be empty.
         * In that case, we have to explicitly set the new variables with
         * putenv, and call proc_open with env=null to inherit the reset
         * of the system.
         *
         * This is kind of crappy because we cannot easily restore just those
         * variables afterwards.
         *
         * If $_ENV is not empty, then we can just copy it and be done with it.
         */
        if (count($_ENV) === 0) {
            $env = NULL;
            foreach ($this->envopts as $k => $v) {
                putenv(sprintf("%s=%s", $k, $v));
            }
        } else {
            $env = array_merge($_ENV, $this->envopts);
        }
        $cwd = $this->currentPath;
        $resource = proc_open($command, $descriptorSpec, $pipes, $cwd, $env);

        $stdout = stream_get_contents($pipes[1]);
        $stderr = stream_get_contents($pipes[2]);
        foreach ($pipes as $pipe) {
            fclose($pipe);
        }

        $status = trim(proc_close($resource));
        if ($status) throw new ConsoleException($stderr . PHP_EOL . $stdout);

        return $stderr . $stdout;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions