pax_global_header00006660000000000000000000000064125105314170014511gustar00rootroot0000000000000052 comment=2d5c139d0eedcb9e67e0e9ca08023be6e9b7b47b git-2.0.1/000077500000000000000000000000001251053141700122745ustar00rootroot00000000000000git-2.0.1/.gitignore000066400000000000000000000000771251053141700142700ustar00rootroot00000000000000/.idea /vendor /composer.lock /composer.phar /cache.properties git-2.0.1/LICENSE000066400000000000000000000030021251053141700132740ustar00rootroot00000000000000Git Copyright (c) 2013-2014, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. git-2.0.1/README.md000066400000000000000000000006011251053141700135500ustar00rootroot00000000000000# Git Simple PHP wrapper for Git. ## Installation To add this package as a local, per-project dependency to your project, simply add a dependency on `sebastian/git` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on Git 1.0: { "require": { "sebastian/git": "1.0.*" } } git-2.0.1/build.xml000066400000000000000000000013631251053141700141200ustar00rootroot00000000000000 git-2.0.1/composer.json000066400000000000000000000010411251053141700150120ustar00rootroot00000000000000{ "name": "sebastian/git", "description": "Simple wrapper for Git", "keywords": ["git"], "homepage": "http://www.github.com/sebastianbergmann/git", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" } ], "require": { "php": ">=5.3.3" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "2.0-dev" } } } git-2.0.1/src/000077500000000000000000000000001251053141700130635ustar00rootroot00000000000000git-2.0.1/src/Exception/000077500000000000000000000000001251053141700150215ustar00rootroot00000000000000git-2.0.1/src/Exception/Exception.php000066400000000000000000000043341251053141700174740ustar00rootroot00000000000000. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @author Sebastian Bergmann * @copyright 2013-2014 Sebastian Bergmann * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License * @link http://www.github.com/sebastianbergmann/git */ namespace SebastianBergmann\Git; /** * @author Sebastian Bergmann * @copyright 2013-2014 Sebastian Bergmann * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License * @link http://www.github.com/sebastianbergmann/git */ interface Exception { } git-2.0.1/src/Exception/RuntimeException.php000066400000000000000000000044161251053141700210410ustar00rootroot00000000000000. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @author Sebastian Bergmann * @copyright 2013-2014 Sebastian Bergmann * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License * @link http://www.github.com/sebastianbergmann/git */ namespace SebastianBergmann\Git; /** * @author Sebastian Bergmann * @copyright 2013-2014 Sebastian Bergmann * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License * @link http://www.github.com/sebastianbergmann/git */ class RuntimeException extends \RuntimeException implements Exception { } git-2.0.1/src/Git.php000066400000000000000000000112161251053141700143200ustar00rootroot00000000000000. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * * Neither the name of Sebastian Bergmann nor the names of his * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * @author Sebastian Bergmann * @copyright 2013-2014 Sebastian Bergmann * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License * @link http://www.github.com/sebastianbergmann/git */ namespace SebastianBergmann\Git; use DateTime; /** * @author Sebastian Bergmann * @copyright 2013-2014 Sebastian Bergmann * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License * @link http://www.github.com/sebastianbergmann/git */ class Git { /** * @var string */ private $repositoryPath; /** * @param string $repositoryPath */ public function __construct($repositoryPath) { $this->repositoryPath = realpath($repositoryPath); } /** * @param string $revision */ public function checkout($revision) { $this->execute( 'git checkout --force --quiet ' . $revision . ' 2>&1' ); } /** * @return string */ public function getCurrentBranch() { $output = $this->execute('git status --porcelain --branch'); $tmp = explode(' ', $output[0]); $tmp = explode('...', $tmp[1]); return $tmp[0]; } /** * @param string $from * @param string $to * @return string */ public function getDiff($from, $to) { $output = $this->execute( 'git diff --no-ext-diff ' . $from . ' ' . $to ); return join("\n", $output); } /** * @return array */ public function getRevisions() { $output = $this->execute( 'git log --no-merges --date-order --reverse --format=medium' ); $numLines = count($output); $revisions = array(); for ($i = 0; $i < $numLines; $i++) { $tmp = explode(' ', $output[$i]); if (count($tmp) == 2 && $tmp[0] == 'commit') { $sha1 = $tmp[1]; } elseif (count($tmp) == 4 && $tmp[0] == 'Author:') { $author = join(' ', array_slice($tmp, 1)); } elseif (count($tmp) == 9 && $tmp[0] == 'Date:') { $revisions[] = array( 'author' => $author, 'date' => DateTime::createFromFormat( 'D M j H:i:s Y O', join(' ', array_slice($tmp, 3)) ), 'sha1' => $sha1, 'message' => isset($output[$i+2]) ? trim($output[$i+2]) : '' ); } } return $revisions; } /** * @param string $command * @throws RuntimeException */ protected function execute($command) { $cwd = getcwd(); chdir($this->repositoryPath); exec($command, $output, $returnValue); chdir($cwd); if ($returnValue !== 0) { throw new RuntimeException(implode("\r\n", $output)); } return $output; } }