Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thrown ConsoleException when git command returns nothing #62

Open
anystar opened this issue Jan 29, 2019 · 1 comment
Open

Thrown ConsoleException when git command returns nothing #62

anystar opened this issue Jan 29, 2019 · 1 comment

Comments

@anystar
Copy link

anystar commented Jan 29, 2019

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;
    }
}
@ppazos
Copy link

ppazos commented Aug 30, 2023

@anystar maybe you can contribute a PR with the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants