2

I am designing an application which has a layer ontop of git that would allow me to perform commits from the web browser instead of having to go CLI. The git repo will be on my own server. Part of the git process is git push origin master, but that has a password prompt.

The exec code

private function run($command, array $arguments = array()) {
    $pipes = array();
    $descriptorspec = array(
       array('pipe', 'r'),  // STDIN
       array('pipe', 'w'),  // STDOUT
       array('file', 'temp/error.txt', 'w'),  // STDERR
    );
    $process = proc_open($command, $descriptorspec, $pipes);
    foreach ($arguments as $arg) {
        // Write each of the supplied arguments to STDIN
        fwrite($pipes[0], (preg_match("/\n(:?\s+)?$/", $arg) ? $arg : "{$arg}\n"));
    }
    $response = stream_get_contents($pipes[1]);
    // Make sure that each pipe is closed to prevent a lockout
    foreach ($pipes as $pipe) {
        fclose($pipe);
    }
    proc_close($process);
    return $response;
}

and I would call the function using

$git->run('git push origin master', array('username', 'password'));

Doing the above does absolutely nothing.

During debugging of the above code, I ran php -i and got some returned data. I then ran aasdashdlashdkashdl, i.e. a script I know doesn't exist, and still got nothing returned and no error output either. Running git status using this function returns an output, whereas git add . returns nothing and does nothing to the git repo.

What am I doing wrong? Can I use certificates instead (but then you have the problem of a self signed certificate, and I may not only develop on my personal computer but others as well)?

NB

I'm trying to stay as "vanilla" as possible, and would rather not have to add loads of packages, although I am willing if there's no other solution.

Luke Madhanga
  • 6,871
  • 2
  • 43
  • 47
  • Does `$CWD/temp/` exist? Is it writable? Does `$CWD/temp/error.txt` exist? Is it writable? What are your exit codes? You can also set STDERR as a pipe and read from it like you would STDOUT. – Sammitch Jan 13 '16 at 23:16
  • @Sammitch Thanks, I'll try that. Yes, CWD/temp/error.txt is writable, but I'll definitely give your suggestion a try – Luke Madhanga Jan 13 '16 at 23:20
  • 1
    @Sammitch I tried your suggestion and indeed, piping STDERR instead of writing it gave me the info that I needed. I didn't have the fully correct reads/writes set on the folder (the group _www could not write to the main git folder so the application terminated) – Luke Madhanga Jan 14 '16 at 23:38
  • Where are you calling `$git->run` from? – bcmcfc Jan 31 '16 at 15:11

0 Answers0