Skip to content

Commit

Permalink
refs #1797 : add - initial plugin commit (does not work yet)
Browse files Browse the repository at this point in the history
 -
  • Loading branch information
inureyes committed Apr 19, 2015
1 parent 879aeb2 commit 5a75e0a
Show file tree
Hide file tree
Showing 4 changed files with 442 additions and 0 deletions.
27 changes: 27 additions & 0 deletions plugins/TestSuite/index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<plugin version="2.0">
<title xml:lang="en">Test suite</title>
<version>0.1</version>
<description xml:lang="en">Receive and autoupdate Textcube code from main repository.</description>
<license>GPL</license>
<link>http://forest.nubimaru.com</link>
<author link="http://forest.nubimaru.com"><![CDATA[Jeongkyu Shin (inureyes)]]></author>
<safety changeData="no" exposeData="yes" accessLocal="yes" accessRemote="yes" accessRaw="yes" />
<requirements>
<textcube>
<minVersion>2.0</minVersion>
</textcube>
</requirements>
<binding>
<config xml:lang="en" dataValHandler="TestSuite_DataHandler">
<window width="500" height="525" />
<fieldset legend="Repository">
<field title="repos" type="radio" name="repos">
<op value="master" checked="checked"><![CDATA[Newest bleeding edge code.]]></op>
<op value="unstable"><![CDATA[Unstable branch]]></op>
<op value="stable"><![CDATA[Stable branch]]></op>
</field>
</fieldset>
</config>
</binding>
</plugin>
71 changes: 71 additions & 0 deletions plugins/TestSuite/library/PHPGit/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

class PHPGit_Command
{
/**
* @var string Real filesystem path of the repository
*/
protected $dir;

/**
* @var string Git command to run
*/
protected $commandString;

/**
* @var boolean Whether to enable debug mode or not
* When debug mode is on, commands and their output are displayed
*/
protected $debug;

/**
* Instanciate a new Git command
*
* @param string $dir real filesystem path of the repository
* @param array $options
*/
public function __construct($dir, $commandString, $debug)
{
$commandString = trim($commandString);

$this->dir = $dir;
$this->commandString = $commandString;
$this->debug = $debug;
}

public function run()
{
$commandToRun = sprintf('cd %s && %s', escapeshellarg($this->dir), $this->commandString);

if($this->debug) {
print $commandToRun."\n";
}

ob_start();
passthru($commandToRun, $returnVar);
$output = ob_get_clean();

if($this->debug) {
print $output."\n";
}

if(0 !== $returnVar) {
// Git 1.5.x returns 1 when running "git status"
if(1 === $returnVar && 0 === strncmp($this->commandString, 'git status', 10)) {
// it's ok
}
else {
throw new GitRuntimeException(sprintf(
'Command %s failed with code %s: %s',
$commandToRun,
$returnVar,
$output
), $returnVar);
}
}

return trim($output);
}
}

class GitRuntimeException extends RuntimeException {}
88 changes: 88 additions & 0 deletions plugins/TestSuite/library/PHPGit/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

/**
* Simple PHP wrapper for Git configuration
*
* @link http://github.com/ornicar/php-git-repo
* @version 1.3.0
* @author Moritz Schwoerer <moritz.schwoerer at gmail dot com>
* @license MIT License
*
* Documentation: http://github.com/ornicar/php-git-repo/blob/master/README.markdown
* Tickets: http://github.com/ornicar/php-git-repo/issues
*/
class PHPGit_Configuration
{
const USER_NAME = 'user.name';
const USER_EMAIL = 'user.email';

/**
* Holds the actual configuration
* @var array
*/
protected $configuration = array();

/**
* Holds the Git repository instance.
* @var PHPGit_Repository
*/
protected $repository;

public function __construct(PHPGit_Repository $gitRepo)
{
$this->repository = $gitRepo;
}

/**
* Get a config option
*
* @param string $configOption The config option to read
* @param mixed $fallback Value will be returned, if $configOption is not set
*
* @return string
*/
public function get($configOption, $fallback = null)
{
if (isset($this->configuration[$configOption])) {
$optionValue = $this->configuration[$configOption];
} else {
if (array_key_exists($configOption, $this->configuration)) {
$optionValue = $fallback;
}

try {
$optionValue = $this->repository->git(sprintf('config --get ' . $configOption));
$this->configuration[$configOption] = $optionValue;
} catch (GitRuntimeException $e) {
$optionValue = $fallback;
$this->configuration[$configOption] = null;
}
}

return $optionValue;
}

/**
* Set or change a *repository* config option
*
* @param string $configOption
* @param mixed $configValue
*/
public function set($configOption, $configValue)
{
$this->repository->git(sprintf('config --local %s %s', $configOption, $configValue));
unset($this->configuration[$configOption]);
}

/**
* Removes a option from local config
*
* @param string $configOption
*/
public function remove($configOption)
{
$this->repository->git(sprintf('config --local --unset %s', $configOption));
unset($this->configuration[$configOption]);
}

}

0 comments on commit 5a75e0a

Please sign in to comment.