/** * @param string $filePath the path to the file from the project root * @return string The raw contents of the file */ public function rawFileContents($filePath) { $result = $this->gitRoot->getCommandResult('show %s:%s', $this->revision, $filePath); if (!$result->wasOk()) { throw new GitException("Could not get contents of {$filePath} at revision {$this}"); } return $result->getOutput(true); }
public function testBasicCommandExec() { $root = new GitRoot(); $command = CommandTest::withStubbedResult($this, ['a57a266'], 0); Diesel::registerInstantiator('Bart\\Shell\\Command', function ($fmt, $dir, $limit, $author, $pretty) use($command) { // Assert that GitRoot sends expected parameters to create the Command $this->assertEquals('git --git-dir=%s log %s --author=%s --format:%s', $fmt, 'command arg 0'); $this->assertEquals('.git', $dir); $this->assertEquals('-1', $limit, 'Limit of commits'); $this->assertEquals('jbraynard', $author); $this->assertEquals('%h', $pretty, 'pretty format'); return $command; }); // Throw something together with a few args interspersed $result = $root->getCommandResult('log %s --author=%s --format:%s', '-1', 'jbraynard', '%h'); $this->assertEquals('a57a266', $result->getOutput(true), 'git log'); }
/** * The output from `git show` with a specific format (--format={$format} flag) * and suppressed diff output (-s flag) * @param string $format One of the formats specified in the "PRETTY FORMAT" section in the * `git-show` man page (https://git-scm.com/docs/git-show) * @param string $exceptionMsg The exception message to output in case the command fails * @return string The output (as a string) of the `git show` command * @throws GitException */ private function gitShowFormatOutput($format, $exceptionMsg) { $result = $this->gitRoot->getCommandResult("show -s --no-color --format='{$format}' {$this->revision}"); if (!$result->wasOk()) { throw new GitException("{$exceptionMsg} at revision {$this}"); } return $result->getOutput(true); }